Files
website/server/middleware/auth.ts
T
2026-09-23 11:44:36 +02:00

12 lines
385 B
TypeScript

const PUBLIC_ROUTES = ['/api/session', '/api/login']
export default defineEventHandler(async (event) => {
const path = event.path.split('?')[0]!
if (!path.startsWith('/api/') || PUBLIC_ROUTES.includes(path)) return
const session = await diarySession(event)
if (!session.data.unlocked) {
throw createError({ statusCode: 401, statusMessage: 'The diary is locked' })
}
})