maxmillianreo
maxmillianreo

Reputation: 11

Laravel JWT Token Always Blacklisted

I am using the tymondesigns/jwt-auth package for my app. I use customClaims to make my token. Here is the code for login :

$token_data = [
        'iss' => new Issuer('AreteHCM'),
        'iat' => new IssuedAt(Carbon::now()) ,
        'exp' => new Expiration(Carbon::now()->addDays(1)),
        'nbf' => new NotBefore(Carbon::now()),
        'sub' => new Subject('AreteHCMS'),
        'jti' => new JwtId('AreteHCM'),
        'user_data' => $user->user,
        'menu_access' => $menu_access,
        'login_time' => Carbon::now(),
];
    
$customClaims = JWTFactory::customClaims($token_data);
$payload = JWTFactory::make($customClaims);
$token = JWTAuth::encode($payload)->get();

For Logout, I invalidate the token, so the token can not be used anymore after the user logout.

JWTAuth::invalidate(JWTAuth::getToken());

I'm creating API (Backend) and the front end team using Angular. Eveythings went smooth, until the user logout and try to login again. After login, the user get the new account, but when he/she wants to access my middleware always rejects the token, it says that the token is blacklisted.

Here is my middleware :

$token = JWTAuth::getToken();
$data = JWTAuth::getPayload($token)->toArray();

It always shows error :

The token has been blacklisted in file C:\xampp\htdocs\aretehcm\vendor\tymon\jwt-auth\src\Manager.php on line 109

What I want to approach is :

Is there any misconception from me about the JWT-API architecture ? Thank you in advance for your replies and answers.

Upvotes: 1

Views: 7414

Answers (1)

Ask17
Ask17

Reputation: 82

A quick google search pointed me towards this solution: https://github.com/tymondesigns/jwt-auth/issues/983#issuecomment-275884324

Upvotes: 0

Related Questions