Basic hook to check col on signin

Hi, If I have a column called active and I want to check when user signs in if active is true or not - how can I do this? Meanwhile have only added email and password auth and added a col called active.
Solution:
In case anyonelooking for the answer ```ts hooks: { before: createAuthMiddleware(async (ctx) => {...
Jump to solution
1 Reply
Solution
johntanzer
johntanzer2mo ago
In case anyonelooking for the answer
hooks: {
before: createAuthMiddleware(async (ctx) => {
if (ctx.path === '/sign-in/email') {
const { email } = ctx.body
const active = await checkIfUserActive(email)
if (!active) {
throw new APIError('UNAUTHORIZED', {
message: 'User account has not been activated'
})
}
}
})
},
hooks: {
before: createAuthMiddleware(async (ctx) => {
if (ctx.path === '/sign-in/email') {
const { email } = ctx.body
const active = await checkIfUserActive(email)
if (!active) {
throw new APIError('UNAUTHORIZED', {
message: 'User account has not been activated'
})
}
}
})
},
i did somethign like this

Did you find this page helpful?