I'm developing the user login part, with a database. However, I'm having difficulty with the login route, where it can't verify my password, what could I be doing wrong? #4548
Unanswered
JoaoLuiz92
asked this question in
Help
Replies: 1 comment
-
What does your user model look like? Do you have the const user = await User.verifyCredentials(email, password) https://docs.adonisjs.com/guides/verifying_user_credentials#using-the-auth-finder-mixin |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
`router.post('login', async ({ request, response }) => {
const { email, password } = request.only(['email', 'password'])
const user = await User.findBy('email', email)
if (!user) {
return response.abort('Invalid')
}
const passwordValid = await hash.verify(user.password, password)
console.log(user.password)
if (passwordValid) {
return response.send('Pass Valid')
} else {
return response.abort('Invalid credentials')
}
/try {
const token = await auth.use('api').generate(user)
return response.json(token)
} catch (err) {
console.error(err)
return response.internalServerError('Something went wrong')
}/`
Beta Was this translation helpful? Give feedback.
All reactions