diff --git a/src/routes/+page.server.ts b/src/routes/+page.server.ts index bd1600f..7fb6e70 100644 --- a/src/routes/+page.server.ts +++ b/src/routes/+page.server.ts @@ -8,5 +8,5 @@ export const load: LayoutServerLoad = async ({ cookies }) => { return redirect(302, '/login'); } - return { authCookie: cookies.get('auth') }; + return { authCookie: cookies.get('auth'), usesAuth: Boolean(env.PASSWORD) }; }; diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index c5454aa..835b961 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -52,8 +52,10 @@ - - + {#if data.usesAuth} + + + {/if} diff --git a/src/routes/login/+page.server.ts b/src/routes/login/+page.server.ts index 79464fc..4f42a77 100644 --- a/src/routes/login/+page.server.ts +++ b/src/routes/login/+page.server.ts @@ -4,6 +4,10 @@ import { fail, redirect } from '@sveltejs/kit'; import { SignJWT } from 'jose'; export const load = async ({ cookies }) => { + if (!env.PASSWORD) { + return redirect(303, '/'); + } + const authCookie = cookies.get('auth'); if (authCookie) { diff --git a/src/routes/logout/+page.server.ts b/src/routes/logout/+page.server.ts index 88f9c36..6e6c27d 100644 --- a/src/routes/logout/+page.server.ts +++ b/src/routes/logout/+page.server.ts @@ -1,6 +1,11 @@ +import { env } from '$env/dynamic/private'; import { redirect } from '@sveltejs/kit'; export const load = ({ cookies }) => { + if (!env.PASSWORD) { + return redirect(303, '/'); + } + cookies.delete('auth', { path: '/' }); return redirect(303, '/login'); };