feat: add notes app
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
const FAILED_LOGIN_DELAY_MS = 1000
|
||||
|
||||
const loginSchema = z.object({
|
||||
password: z.string().min(1)
|
||||
})
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const { password } = await readValidBody(event, loginSchema)
|
||||
|
||||
if (!(await passwordMatches(event, password))) {
|
||||
await new Promise(resolve => setTimeout(resolve, FAILED_LOGIN_DELAY_MS))
|
||||
throw createError({ statusCode: 401, statusMessage: 'Wrong password' })
|
||||
}
|
||||
|
||||
const session = await authSession(event)
|
||||
await session.update({ unlocked: true })
|
||||
return { unlocked: true }
|
||||
})
|
||||
@@ -0,0 +1,4 @@
|
||||
export default defineEventHandler(async (event) => {
|
||||
const session = await authSession(event)
|
||||
return { unlocked: !!session.data.unlocked }
|
||||
})
|
||||
Reference in New Issue
Block a user