fix redirect
This commit is contained in:
parent
8ba0297cfd
commit
38021f0453
2 changed files with 12 additions and 14 deletions
|
|
@ -1,17 +1,17 @@
|
||||||
import { prisma } from '$lib/server/prisma';
|
import { prisma } from '$lib/server/prisma';
|
||||||
|
import { redirect } from '@sveltejs/kit';
|
||||||
export async function load(event) {
|
export async function load(event) {
|
||||||
const userId = event.cookies.get('user');
|
const sessionId = event.cookies.get('auth_session');
|
||||||
if (!userId) {
|
if (!sessionId) {
|
||||||
return {
|
redirect(303, '/login');
|
||||||
authenticated: false,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
const user = await prisma.user.findUnique({
|
const user = await prisma.session.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id: userId,
|
id: sessionId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
return {
|
if (!user) {
|
||||||
authenticated: !!user,
|
redirect(401, '/login');
|
||||||
};
|
}
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,8 @@
|
||||||
import Loader from '$lib/components/common/Loader';
|
import Loader from '$lib/components/common/Loader';
|
||||||
import { fade } from 'svelte/transition';
|
import { fade } from 'svelte/transition';
|
||||||
|
|
||||||
let { data } = $props();
|
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
const id = setTimeout(() => (data.authenticated ? goto('/app') : goto('/login')), 1500);
|
const id = setTimeout(() => goto('/app'), 1500);
|
||||||
return () => {
|
return () => {
|
||||||
clearTimeout(id);
|
clearTimeout(id);
|
||||||
};
|
};
|
||||||
|
|
@ -21,4 +19,4 @@
|
||||||
.site-loader {
|
.site-loader {
|
||||||
@apply flex h-screen w-screen flex-col items-center justify-center gap-6;
|
@apply flex h-screen w-screen flex-col items-center justify-center gap-6;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
Loading…
Add table
Reference in a new issue