Files
Musify/web-player/src/hooks.server.ts
T
Admin 546aef6d83 refactor: rename frontend/ to web-player/ and format with prettier
Updates the compose build context, the Dockerfile header, the package
name and the docs. The compose service and container keep the name
frontend/musify-frontend, since nginx routes to http://frontend:3000.

The source files also carry the first prettier pass, so the rename and
the reformat land together for them.
2026-07-20 07:35:01 +02:00

45 lines
1016 B
TypeScript

import type { Handle } from '@sveltejs/kit';
import {
decodeSession,
encodeSession,
refreshSession,
sessionCookieOptions,
SESSION_COOKIE
} from '$lib/server/auth';
import { authConfig } from '$lib/server/config';
export const handle: Handle = async ({ event, resolve }) => {
let session = await decodeSession(event.cookies.get(SESSION_COOKIE));
if (
session &&
session.expiresAt - authConfig.refreshThresholdSeconds <= Math.floor(Date.now() / 1000)
) {
session = await refreshSession(session);
if (session) {
event.cookies.set(
SESSION_COOKIE,
await encodeSession(session),
sessionCookieOptions(event.url)
);
} else {
event.cookies.delete(SESSION_COOKIE, { path: '/' });
}
}
if (session) {
event.locals.user = {
sub: session.sub,
name: session.name,
email: session.email,
picture: session.picture
};
event.locals.accessToken = session.accessToken;
} else {
event.locals.user = null;
event.locals.accessToken = null;
}
return resolve(event);
};