add admin login

This commit is contained in:
2023-08-27 23:33:22 +02:00
parent 7392b61e3e
commit 4b84c475b8
16 changed files with 377 additions and 44 deletions

View File

@@ -1,4 +1,25 @@
import { sequelize } from '$lib/server/database';
import type { Handle } from '@sveltejs/kit';
import { env } from '$env/dynamic/public';
import { hasSession } from '$lib/server/session';
// make sure that the database and tables exist
await sequelize.sync();
export const handle: Handle = async ({ event, resolve }) => {
if (
event.url.pathname.startsWith(`${env.PUBLIC_BASE_PATH}/admin`) &&
event.url.pathname != `${env.PUBLIC_BASE_PATH}/admin/login`
) {
if (!hasSession(event.cookies.get('session') || '')) {
return new Response(null, {
status: 302,
headers: {
location: `${env.PUBLIC_BASE_PATH}/admin/login`
}
});
}
}
return resolve(event);
};