Basic auth

This commit is contained in:
2025-01-15 18:20:27 -06:00
parent 28c18e249c
commit f0fc8b09ab
15 changed files with 332 additions and 26 deletions
+19
View File
@@ -1,5 +1,24 @@
import jwt from 'jsonwebtoken';
import * as dotenv from 'dotenv';
dotenv.config({ path: '.env' });
export const handle = async ({ event, resolve }) => {
const theme = event.cookies.get('theme');
const JWT = event.cookies.get('jwt');
if (process.env.JWT_SECRET === undefined) {
throw new Error('JWT_SECRET not defined');
}
if (JWT) {
try {
const decoded = jwt.verify(JWT, process.env.JWT_SECRET);
} catch (err) {
event.cookies.delete('jwt', { path: '/' });
}
}
if (!theme) {
return await resolve(event);
}