base layout and redirect on root when not logged in
This commit is contained in:
parent
7511b891fc
commit
710eadf5c0
4 changed files with 32 additions and 9 deletions
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.navbar {
|
.navbar {
|
||||||
@apply flex items-center justify-between border-slate-200 bg-slate-100 px-6 py-2 font-display drop-shadow;
|
@apply flex items-center justify-between border-b border-slate-200 bg-slate-50 px-6 py-2 font-display drop-shadow;
|
||||||
}
|
}
|
||||||
|
|
||||||
.navbar h1 {
|
.navbar h1 {
|
||||||
|
|
|
||||||
|
|
@ -3,4 +3,12 @@
|
||||||
let { children } = $props();
|
let { children } = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{@render children()}
|
<div class="layout">
|
||||||
|
{@render children()}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.layout {
|
||||||
|
@apply h-screen w-screen bg-slate-100;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
18
src/routes/+page.server.ts
Normal file
18
src/routes/+page.server.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
import { prisma } from '$lib/server/prisma';
|
||||||
|
|
||||||
|
export async function load(event) {
|
||||||
|
const userId = event.cookies.get('user');
|
||||||
|
if (!userId && isNaN(Number(userId))) {
|
||||||
|
return {
|
||||||
|
authenticated: false
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const user = await prisma.user.findUnique({
|
||||||
|
where: {
|
||||||
|
id: Number(userId)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
authenticated: !!user
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -2,10 +2,10 @@
|
||||||
import { goto } from '$app/navigation';
|
import { goto } from '$app/navigation';
|
||||||
import Loader from '$lib/components/Loader.svelte';
|
import Loader from '$lib/components/Loader.svelte';
|
||||||
|
|
||||||
|
let { data } = $props();
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
const id = setTimeout(() => {
|
const id = setTimeout(() => (data.authenticated ? goto('/app') : goto('/login')), 1500);
|
||||||
goto('/app');
|
|
||||||
}, 1500);
|
|
||||||
return () => {
|
return () => {
|
||||||
clearTimeout(id);
|
clearTimeout(id);
|
||||||
};
|
};
|
||||||
|
|
@ -19,9 +19,6 @@
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.site-loader {
|
.site-loader {
|
||||||
@apply flex h-screen w-screen flex-col items-center justify-center gap-6 bg-slate-100;
|
@apply flex h-screen w-screen flex-col items-center justify-center gap-6;
|
||||||
}
|
|
||||||
.site-loader h1 {
|
|
||||||
@apply font-display text-4xl;
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
Loading…
Add table
Reference in a new issue