I had also faces the simile difficulty, and there is no direct solution for that, so after auth
attempt
I added my own method/logic to check the same.
Here is a sample code for that.
public function login(Request $request)
{
try
{
$credentials = $request->only(['email', 'password']);
if (!$token = auth()->attempt($credentials))
{
return response()->json(['error' => 'invalid credentials'], 401);
}
//if you reached here then user has been authenticated
if (empty(auth()->user()->email_verified_at))
{
return response()->json(['error' => 'Your have not verified your email.'], 401);
}
return response()->json([
'access_token' => $token,
'token_type' => 'bearer',
'expires_in' => auth()->factory()->getTTL() * 60
], 200);
}
catch (JWTException $e)
{
// something went wrong whilst attempting to encode the token
return response()->json(['error' => 'could not create token'], 500);
}
}
Please Note: In the above example I used tymon/jwt-auth v1.0
& Laravel v7
Hope this helps!
authenticate()
after grabbing credentials – Tarasovych