yii2-jwt
yii2-jwt copied to clipboard
Returns error code 500 instead of 401 when token is expired
Version 4.0-beta returns error code 500 instead of 401 when token is expired: The token violates some mandatory constraints, details:
- The token is expired
To fix this, create a new file called TokenExpiredFilter.php
in your filters directory (just create a folder called 'filters' in your project directory)
Then add this code into the file: https://gist.github.com/cozumel424/02461064e5d227a031d26bddaf9322c9
And then in your base controller:
//add this above (so it runs first) the Jwt code
$behaviors['tokenExpiredFilter'] = [
'class' => 'app\filters\TokenExpiredFilter',
];
$behaviors['authenticator'] = [
'class' => JwtHttpBearerAuth::class,
];