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