diff --git a/frontend/.prettierignore b/frontend/.prettierignore index ab78a95d..9ad56c28 100644 --- a/frontend/.prettierignore +++ b/frontend/.prettierignore @@ -2,3 +2,7 @@ package-lock.json pnpm-lock.yaml yarn.lock + +# Compiled files +.svelte-kit/ +build/ \ No newline at end of file diff --git a/frontend/src/hooks.server.ts b/frontend/src/hooks.server.ts index cead04c5..d98dfab0 100644 --- a/frontend/src/hooks.server.ts +++ b/frontend/src/hooks.server.ts @@ -27,13 +27,11 @@ const authenticationHandle: Handle = async ({ event, resolve }) => { const isPublicPath = ['/authorize', '/health'].includes(event.url.pathname); const isAdminPath = event.url.pathname.startsWith('/settings/admin'); - if (!isUnauthenticatedOnlyPath && !isPublicPath) { - if (!isSignedIn) { - return new Response(null, { - status: 302, - headers: { location: '/login' } - }); - } + if (!isUnauthenticatedOnlyPath && !isPublicPath && !isSignedIn) { + return new Response(null, { + status: 302, + headers: { location: '/login' } + }); } if (isUnauthenticatedOnlyPath && isSignedIn) { @@ -81,7 +79,7 @@ function verifyJwt(accessToken: string | undefined) { const jwtPayload = decodeJwt<{ isAdmin: boolean }>(accessToken); if (jwtPayload?.exp && jwtPayload.exp * 1000 > Date.now()) { isSignedIn = true; - isAdmin = jwtPayload?.isAdmin || false; + isAdmin = !!(jwtPayload?.isAdmin); } } diff --git a/frontend/src/routes/+page.server.ts b/frontend/src/routes/+page.server.ts deleted file mode 100644 index 4ffa51f0..00000000 --- a/frontend/src/routes/+page.server.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { redirect } from '@sveltejs/kit'; -import type { PageServerLoad } from './$types'; - -export const load: PageServerLoad = async () => { - return redirect(302, '/login'); -}; diff --git a/frontend/src/routes/+page.ts b/frontend/src/routes/+page.ts new file mode 100644 index 00000000..85dc086a --- /dev/null +++ b/frontend/src/routes/+page.ts @@ -0,0 +1,6 @@ +import { redirect } from '@sveltejs/kit'; +import type { PageLoad } from './$types'; + +export const load: PageLoad = async () => { + return redirect(302, '/login'); +}; diff --git a/frontend/src/routes/lc/+server.ts b/frontend/src/routes/lc/+page.ts similarity index 75% rename from frontend/src/routes/lc/+server.ts rename to frontend/src/routes/lc/+page.ts index 9a8b88f4..f4f72eb1 100644 --- a/frontend/src/routes/lc/+server.ts +++ b/frontend/src/routes/lc/+page.ts @@ -1,7 +1,8 @@ import { redirect } from '@sveltejs/kit'; +import type { PageLoad } from './$types'; // Alias for /login/alternative/code -export function GET({ url }) { +export const load: PageLoad = async ({ url }) => { let targetPath = '/login/alternative/code'; if (url.searchParams.has('redirect')) { targetPath += `?redirect=${encodeURIComponent(url.searchParams.get('redirect')!)}`; diff --git a/frontend/src/routes/lc/[code]/+server.ts b/frontend/src/routes/lc/[code]/+page.ts similarity index 80% rename from frontend/src/routes/lc/[code]/+server.ts rename to frontend/src/routes/lc/[code]/+page.ts index 293cc327..beeb6ce5 100644 --- a/frontend/src/routes/lc/[code]/+server.ts +++ b/frontend/src/routes/lc/[code]/+page.ts @@ -1,7 +1,8 @@ import { redirect } from '@sveltejs/kit'; +import type { PageLoad } from './$types'; // Alias for /login/alternative/code?code=... -export function GET({ url, params }) { +export const load: PageLoad = async ({ url, params }) => { const targetPath = '/login/alternative/code'; const searchParams = new URLSearchParams(); diff --git a/frontend/src/routes/login/alternative/code/+page.server.ts b/frontend/src/routes/login/alternative/code/+page.ts similarity index 52% rename from frontend/src/routes/login/alternative/code/+page.server.ts rename to frontend/src/routes/login/alternative/code/+page.ts index 2547b4ff..55d086ef 100644 --- a/frontend/src/routes/login/alternative/code/+page.server.ts +++ b/frontend/src/routes/login/alternative/code/+page.ts @@ -1,6 +1,6 @@ -import type { PageServerLoad } from './$types'; +import type { PageLoad } from './$types'; -export const load: PageServerLoad = async ({ url }) => { +export const load: PageLoad = async ({ url }) => { return { code: url.searchParams.get('code'), redirect: url.searchParams.get('redirect') || '/settings' diff --git a/frontend/src/routes/login/alternative/email/+page.server.ts b/frontend/src/routes/login/alternative/email/+page.server.ts deleted file mode 100644 index cfa9d995..00000000 --- a/frontend/src/routes/login/alternative/email/+page.server.ts +++ /dev/null @@ -1,7 +0,0 @@ -import type { PageServerLoad } from './$types'; - -export const load: PageServerLoad = async ({ url }) => { - return { - redirect: url.searchParams.get('redirect') || undefined - }; -}; diff --git a/frontend/src/routes/login/alternative/email/+page.ts b/frontend/src/routes/login/alternative/email/+page.ts new file mode 100644 index 00000000..91e1e48d --- /dev/null +++ b/frontend/src/routes/login/alternative/email/+page.ts @@ -0,0 +1,7 @@ +import type { PageLoad } from './$types'; + +export const load: PageLoad = async ({ url }) => { + return { + redirect: url.searchParams.get('redirect') || undefined + }; +}; diff --git a/frontend/src/routes/settings/+page.server.ts b/frontend/src/routes/settings/+page.ts similarity index 50% rename from frontend/src/routes/settings/+page.server.ts rename to frontend/src/routes/settings/+page.ts index 84ed8e02..0806fad0 100644 --- a/frontend/src/routes/settings/+page.server.ts +++ b/frontend/src/routes/settings/+page.ts @@ -1,5 +1,6 @@ import { redirect } from '@sveltejs/kit'; +import type { PageLoad } from './$types'; -export function load() { +export const load: PageLoad = async () => { throw redirect(307, '/settings/account'); }