fix: Add session checking in server layout
This commit is contained in:
parent
364846eeed
commit
08493a24b7
@ -2,6 +2,7 @@ import { db } from '$lib/server/db';
|
|||||||
import { auth } from '$lib/server/db/auth';
|
import { auth } from '$lib/server/db/auth';
|
||||||
import { authdb } from '$lib/server/db/sqlite.js';
|
import { authdb } from '$lib/server/db/sqlite.js';
|
||||||
import { newChannelSchema } from '$lib/types/misc';
|
import { newChannelSchema } from '$lib/types/misc';
|
||||||
|
import { redirect } from '@sveltejs/kit';
|
||||||
import { superValidate } from 'sveltekit-superforms';
|
import { superValidate } from 'sveltekit-superforms';
|
||||||
import { zod } from 'sveltekit-superforms/adapters';
|
import { zod } from 'sveltekit-superforms/adapters';
|
||||||
|
|
||||||
@ -11,6 +12,14 @@ interface Profile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function load({ request }) {
|
export async function load({ request }) {
|
||||||
|
const session = await auth.api.getSession({
|
||||||
|
headers: request.headers,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!session) {
|
||||||
|
redirect(307, '/signup');
|
||||||
|
}
|
||||||
|
|
||||||
const form = await superValidate(zod(newChannelSchema));
|
const form = await superValidate(zod(newChannelSchema));
|
||||||
const rows = await db.getChannels();
|
const rows = await db.getChannels();
|
||||||
const channels: string[] = rows
|
const channels: string[] = rows
|
||||||
@ -19,10 +28,6 @@ export async function load({ request }) {
|
|||||||
})
|
})
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
const session = await auth.api.getSession({
|
|
||||||
headers: request.headers,
|
|
||||||
});
|
|
||||||
|
|
||||||
let user: Profile;
|
let user: Profile;
|
||||||
|
|
||||||
if (session?.user.id) {
|
if (session?.user.id) {
|
||||||
|
Loading…
Reference in New Issue
Block a user