Laravel and JWT - Does not generate token (invalid credentials)

Asked

Viewed 111 times

2

I’m having a problem using the following code:

$credentials = $request->only('email', 'senha');
try {
   if(! $token = JWTAuth::attempt($credentials)){
     return response()->json(['error' => 'invalid_credentials'], 400);
   }
}catch(JWTException $e){
   return response()->json(['error' => 'could_not_create_token'], 500);
}

return response()->json([
  'access_token'  => $token,
  'token_type'    => 'bearer',
  'expires_in'    => auth()->factory()->getTTL() * 60
]);

When I used on a user created to the standards of Laravel, the authentication worked perfectly, but... when I changed to my database, I could no longer do the validation.

The user password is encrypted with bcrypt, when making a Hash::check(), the return is true, however, the validation of JWT is always returning me false.

I checked some articles like that of the feature itself and some others only that I could not find the solution!

The Laravel version is 5.2!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.