First pass

This commit is contained in:
2025-12-25 22:10:06 -07:00
parent a2af6195f9
commit 455c3dbd9a
58 changed files with 10299 additions and 3 deletions

25
src/middleware.ts Normal file
View File

@@ -0,0 +1,25 @@
import { defineMiddleware } from 'astro/middleware';
import { validateSession } from './lib/auth';
export const onRequest = defineMiddleware(async (context, next) => {
const sessionId = context.cookies.get('session_id')?.value;
if (!sessionId) {
context.locals.user = null;
context.locals.session = null;
return next();
}
const result = await validateSession(sessionId);
if (result) {
context.locals.user = result.user;
context.locals.session = result.session;
} else {
context.locals.user = null;
context.locals.session = null;
context.cookies.delete('session_id');
}
return next();
});