diff --git a/src/hooks.server.ts b/src/hooks.server.ts index 19900a18..19e3ec8a 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -2,42 +2,41 @@ import { getUserDetails } from '$lib/stores/authStore' import type { Handle } from '@sveltejs/kit' export const handle: Handle = async ({ event, resolve }) => { - const userId = event.url.searchParams.get('userId') || event.cookies.get('userId') - let token = event.url.searchParams.get('token') || event.cookies.get('token') || '' - let user - - if (event.locals && event.locals.user) { - user = event.locals.user.user - } - - if (!token || !userId) { - return await resolve(event) - } - - if (token && userId) { - if (!user) { - const response = await getUserDetails(token, userId) - if (response) { - if (response.freshJwt) { - token = response.freshJwt - } - user = response.user - } - } - - event.cookies.set('token', token) - event.cookies.set('userId', userId) - event.locals.user = { - userId, - token, - user - } - } - - return await resolve(event) + const userId = event.url.searchParams.get('userId') || event.cookies.get('userId') || '' + let token = event.url.searchParams.get('token') || event.cookies.get('token') || '' + let user + + if (event.locals && event.locals.user) { + user = event.locals.user.user + } + + if (!token || !userId) { + return await resolve(event) + } + + if (token && userId) { + if (!user) { + const response = await getUserDetails(token, userId) + if (response) { + if (response.freshJwt) { + token = response.freshJwt + } + user = response.user + } + } + + event.cookies.set('token', token) + event.cookies.set('userId', userId) + event.locals.user = { + userId, + token, + user + } + } + + return await resolve(event) } - // const isAdminPage = /^\/admin\/(.*)/.test(route.id) // const isProfilePage = /^\/profile\/(.*)/.test(route.id) // const isPremiumPage = /^\/premium\/(.*)/.test(route.id) @@ -60,11 +59,6 @@ export const handle: Handle = async ({ event, resolve }) => { // } // } - - - - - // import { remoteConfigStore } from '$lib/stores/remoteConfigStore' // import type { Handle, HandleServerError, RequestEvent } from '@sveltejs/kit' // import type { MaybePromise } from '@sveltejs/kit/types/private' diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 1e0e40c8..678cd290 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -123,14 +123,13 @@ Admin - {:else} -