mardi 17 décembre 2019

Jwt authentication problem - invalid credentials

When i used the auth on created user in Laravel, it's works, but... when I changed to my database, I could no longer validate it.

The user's password is encrypted with bcrypt, when doing a Hash::check(), the return is true, but JWT validation is always returning me false.

I have 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
]);

I checked some articles like this from the resource page itself and some others just couldn't find the solution!

The laravel version is 5.2!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire