diff --git a/composer.json b/composer.json index a5343ec..65c8110 100644 --- a/composer.json +++ b/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": "^7.4", - "laravel/framework": "^6.0 | ^7.0 | ^8.0", - "rbdwllr/reallysimplejwt": "^2.1" + "laravel/framework": "^6.0 | ^7.24.0 | ^8.0", + "rbdwllr/reallysimplejwt": "^2.0" }, "require-dev": { "orchestra/testbench": "^4.0", diff --git a/config/config.php b/config/config.php index 35e8a50..3de8a79 100644 --- a/config/config.php +++ b/config/config.php @@ -1,5 +1,7 @@ 'jwt', 'driver' => 'jwt', 'provider' => 'jwt', + 'policy' => function (Request $request, Authenticatable $user = null) { + if( + method_exists($user, 'hasPendingConfirmation') && + $user->hasPendingConfirmation() + ) return null; + }, ]; diff --git a/src/JwtGuard.php b/src/JwtGuard.php index 474232b..ef948c2 100644 --- a/src/JwtGuard.php +++ b/src/JwtGuard.php @@ -50,8 +50,13 @@ public function user() $token = $this->getPosibleToken($this->request); $userId = $this->tokenService->getAuthIdentifier($token); + + // TODO: verificar contra Exception caso de token no vĂ¡lido contra user not found + if (blank($userId)) return null; - $this->user = $this->provider->retrieveById($userId); + $this->user = $this->evaluatePolicy( + $this->provider->retrieveById($userId) + ); return $this->user; } @@ -87,9 +92,28 @@ protected function getPosibleToken(Request $request) return ''; } - + + protected function evaluatePolicy($user = null): ?Authenticatable + { + return call_user_func_array( + config('jwt-auth.policy'), + [$this->request, $user] + ); + } + public function viaRemember() { + logger(__METHOD__); return false; } + + public function logout() + { + logger(__METHOD__); + } + + public function logoutCurrentDevice() + { + logger(__METHOD__); + } }