1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-26 00:09:38 +02:00
AdventureLog/frontend/src/routes/+page.server.ts

54 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-07-08 11:44:39 -04:00
const PUBLIC_SERVER_URL = process.env['PUBLIC_SERVER_URL'];
import { redirect, type Actions } from '@sveltejs/kit';
const serverEndpoint = PUBLIC_SERVER_URL || 'http://localhost:8000';
export const actions: Actions = {
setTheme: async ({ url, cookies }) => {
const theme = url.searchParams.get('theme');
// change the theme only if it is one of the allowed themes
if (
theme &&
[
'light',
'dark',
'night',
'retro',
'forest',
'aqua',
'forest',
'aestheticLight',
'aestheticDark',
'emerald'
].includes(theme)
2024-07-08 11:44:39 -04:00
) {
cookies.set('colortheme', theme, {
path: '/',
maxAge: 60 * 60 * 24 * 365
});
}
},
logout: async ({ cookies }: { cookies: any }) => {
const cookie = cookies.get('auth') || null;
if (!cookie) {
return;
}
const res = await fetch(`${serverEndpoint}/auth/logout/`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Cookie: cookies.get('auth')
}
});
if (res.ok) {
2024-07-11 19:27:03 -04:00
cookies.delete('auth', { path: '/', secure: false });
cookies.delete('refresh', { path: '/', secure: false });
2024-07-08 11:44:39 -04:00
return redirect(302, '/login');
} else {
return redirect(302, '/');
}
}
};