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