Forráskód Böngészése

fix: :bug: refreshTokenDTO

Denis 1 éve
szülő
commit
656acb3c03

+ 1 - 1
app/DTO/RefreshTokenDTO.php

@@ -7,7 +7,7 @@
 readonly class RefreshTokenDTO
 {
     public function __construct(
-        public string $refresh_token,
+        public ?string $refresh_token = null,
     ) {
     }
 

+ 0 - 2
app/Http/Controllers/AuthController.php

@@ -39,8 +39,6 @@ public function refresh(RefreshTokenRequest $request): JsonResponse
     {
         $tokens = $this->authService->refresh(refreshToken: RefreshTokenDTO::fromRequest(request: $request));
         if (is_null(value: $tokens)) {
-            // It should never reach this point, but just in case
-            Log::error(message: 'Unauthorized');
             return $this->errorResponse(message: __(key: 'auth.unauthorized'), code: 403);
         }
         return $this->successResponse(payload: new AuthResource(resource: $tokens));

+ 1 - 1
app/Http/Requests/RefreshTokenRequest.php

@@ -9,7 +9,7 @@ class RefreshTokenRequest extends FormRequest
     public function rules(): array
     {
         return [
-            'refresh_token' => 'required|string',
+            'refresh_token' => 'string|nullable',
         ];
     }
 }

+ 4 - 0
app/Services/AuthService.php

@@ -36,6 +36,10 @@ public function login(AuthDTO $credentials): ?array
 
     public function refresh(RefreshTokenDTO $refreshToken): ?array
     {
+        if (!$refreshToken->refresh_token) {
+            return null;
+        }
+
         $tokenModel = $this->authRepository->findToken($refreshToken->refresh_token);
 
         if (!$tokenModel || !in_array(needle: 'refresh', haystack: $tokenModel->abilities) || $tokenModel->expires_at < now()) {