Skip to content

Commit

Permalink
feat: verify user
Browse files Browse the repository at this point in the history
  • Loading branch information
qin-guan committed Sep 19, 2023
1 parent eed789f commit 3c6f425
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions server/api/auth/verify.post.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { z } from 'zod'

const verifyRequestBody = z.object({
email: z.string().email(),
})

export default defineCachedEventHandler(async (event) => {
const result = await verifyRequestBody.safeParseAsync(await readBody(event))
if (!result.success) {
throw createError({
status: 400,
statusMessage: 'Bad request',
})
}

const { data } = result

const user = await event.context.database.query.users.findFirst({
where: (users, { eq }) => eq(users.email, data.email),
})

if (user === null) {
throw createError({
status: 404,
statusMessage: 'Not found',
})
}

return { ok: true }
}, {
maxAge: 60 * 60 * 24,
})

0 comments on commit 3c6f425

Please # to comment.