A user's authentication returns the token, but it is not saved in the database
AuthController:
'use strict'
const User = use("App/Models/User");
class AuthController {
async registrar({ request }) {
const data = request.only(["username", "email", "password"]);
const user = await User.create(data);
return user;
}
async autenticar({ request, auth }) {
const { email, password } = request.all();
const retorno = {};
let token;
if (token = await auth.attempt(email, password)) {
const user = await User.findBy('email', email)
retorno.token = token.token;
retorno.user = user.username;
retorno.id = user.id;
} else {
retorno.data = "E-mail ou senha Incorretos";
}
return retorno;
}
}
module.exports = AuthController
My Request
POST http://localhost:3333/autenticar
{
"email":"[email protected]",
"password": "123456"
}
My Response
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjEsImlhdCI6MTYxNTI5Njk4MH0.O0X4gGIEtMiZfEH3VxWbffsCZQDUhgEv0CymA0dB6z8",
"user": "gui",
"id": 1
}
My tokens table after the request 0 tokens
I found the same question on another site, but I didn't have an answer that would help.