add admin login
This commit is contained in:
@@ -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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user