A
A
Alexey2018-09-16 05:31:58
JavaScript
Alexey, 2018-09-16 05:31:58

How to get a token in AdonisJs during authorization?

Good afternoon!
Understanding JWT authorization in the AdonisJs framework.
The following code should return a token:

async login({ request, auth, response }) {        
     try {
            const data = request.all();
            const { email, password } = data;
            const token = await auth.attempt(email, password);

            return token;
     } catch(e) {
            return response.status(422).send({ error: "login error" });
     }
}

The result should be:
{
  type: 'type',
  token: '.....',
  refreshToken: '....'
}

But for some reason it returns user data.
I did not change the default settings, except for the csrf.enable = false parameter in the config/shield.js file

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2018-09-16
@MrSen

Understood, the solution is as follows:
in the config/auth.js file, you must specify the authorization type authenticator = jwt

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question