Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Break after Persona.verify(payload) #36

Open
danielsalles opened this issue Sep 17, 2019 · 3 comments
Open

Break after Persona.verify(payload) #36

danielsalles opened this issue Sep 17, 2019 · 3 comments
Labels

Comments

@danielsalles
Copy link

If I enter the wrong credentials the application breaks in the following.
Captura de tela de 2019-09-17 19-45-02

Wasn't it just returning the error for not being able to log in?

  async login ({ request, response, auth }) {
    const payload = request.only(['uid', 'password'])

    const user = await Persona.verify(payload)

    return await auth.generate(user)
  }
@thetutlage
Copy link
Member

Mind sharing the code for the exception handler and routes file too?

@danielsalles
Copy link
Author

Routes:

const Route = use('Route')

Route
.post('login', 'User/UserController.login')

Route
  .resource('users', 'User/UserController')
  .apiOnly()

No exception is displayed on the terminal. And I didn't make any modifications to another part of the code. I am believing it to be because I started my project without --api-only.
Do I have to change anything to prevent verify from redirect to theGET /router? I just want the API.

@thiago-slb
Copy link

thiago-slb commented Dec 17, 2019

@danielsalles create your own exception handler:

1 - Run: adonis make:ehandler
2 - Change your handle method to this:

async handle (error, { request, response }) {
let errorResponse;
if(error.messages){
errorResponse = error.messages;
} else {
errorResponse = error.message;
}
response.status(error.status).send(errorResponse)
}

Try that and see if this works for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants