Laravel and Lumen Package For JWT

⬇️ How to install and config imanrjb/jwt-auth package?
Install package
composer require imanrjb/jwt-auth
Config package
// Add this lines in "App\Providers\AuthServiceProvider"
public function boot(): void
{
$this->app['auth']->viaRequest('api', function ($request) {
$token = $request->bearerToken();
if($token) {
return AccessToken::checkToken($token);
}
return;
});
}
// Change the "config/auth.php" file
'defaults' => [
'guard' => 'api',
'passwords' => 'users',
],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'api',
'provider' => 'users',
],
],
# Add this items to .env file
JWT_SECRET=GKPMVOCKpMHHJQ3GprVA0EfTKGJi7227mjeKN009Vndls70226raawkRzDoB97AI
ACCESS_TOKEN_LIFETIME=120
REFRESH_TOKEN_LIFETIME=1200
📖 How to use in routes as middleware
Route::get('user', function () {
return auth()->user();
})->middleware('auth:api');