mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2026-07-30 15:28:30 -04:00
Enhance theme handling in hooks.server.ts by introducing a set of allowed theme names and updating theme resolution logic to validate against this set.
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import type { Handle } from '@sveltejs/kit';
|
||||
import { sequence } from '@sveltejs/kit/hooks';
|
||||
import { themes } from '$lib';
|
||||
|
||||
const PUBLIC_SERVER_URL = process.env['PUBLIC_SERVER_URL'];
|
||||
const ALLOWED_THEME_NAMES = new Set(themes.map((theme) => theme.name));
|
||||
|
||||
export const authHook: Handle = async ({ event, resolve }) => {
|
||||
event.cookies.delete('csrftoken', { path: '/' });
|
||||
@@ -88,7 +91,8 @@ export const authHook: Handle = async ({ event, resolve }) => {
|
||||
};
|
||||
|
||||
export const themeHook: Handle = async ({ event, resolve }) => {
|
||||
let theme = event.url.searchParams.get('theme') || event.cookies.get('colortheme');
|
||||
const candidate = event.url.searchParams.get('theme') || event.cookies.get('colortheme');
|
||||
const theme = candidate && ALLOWED_THEME_NAMES.has(candidate) ? candidate : null;
|
||||
|
||||
if (theme) {
|
||||
return await resolve(event, {
|
||||
|
||||
Reference in New Issue
Block a user