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