Selaa lähdekoodia

fix: :bug: bug

Denis 1 vuosi sitten
vanhempi
commit
c6dae88f2e

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

@@ -9,6 +9,7 @@
 use App\Http\Resources\AuthResource;
 use App\Services\AuthService;
 use App\DTO\RefreshTokenDTO;
+use Illuminate\Support\Facades\Log;
 
 class AuthController extends Controller
 
@@ -38,6 +39,8 @@ 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));

+ 4 - 3
app/Services/AuthService.php

@@ -12,7 +12,8 @@ class AuthService
 {
     public function __construct(
         protected AuthRepositoryInterface $authRepository,
-    ) {}
+    ) {
+    }
 
     public function login(AuthDTO $credentials): ?array
     {
@@ -36,7 +37,7 @@ public function login(AuthDTO $credentials): ?array
 
     public function refresh(RefreshTokenDTO $refreshToken): ?array
     {
-        $tokenModel = $this->authRepository->findToken(token: $refreshToken->token);
+        $tokenModel = $this->authRepository->findToken( $refreshToken->token);
 
         if (!$tokenModel || !in_array(needle: 'refresh', haystack: $tokenModel->abilities) || $tokenModel->expires_at < now()) {
             return null;
@@ -49,7 +50,7 @@ public function refresh(RefreshTokenDTO $refreshToken): ?array
 
         $deviceId = Str::afterLast(subject: $tokenModel->name, search: '_');
 
-        $tokens = $this->authRepository->refreshToken(token: $tokenModel, user: $user, deviceId: $deviceId);
+        $tokens = $this->authRepository->refreshToken($tokenModel, $user, $deviceId);
 
         return array_merge($tokens, [
             'user' => $user,

+ 3 - 3
database/seeders/UserSeeder.php

@@ -14,9 +14,9 @@ class UserSeeder extends Seeder
     public function run(): void
     {
         $user = User::firstOrNew(attributes: [
-            'name' => 'admin',
-            'email' => 'admin@admin.com',
-            'password' => bcrypt(value: 'admin'),
+            'name' => 'suporte',
+            'email' => 'suporte@softpar.inf.br',
+            'password' => 'S@ft2080.',
             'type' => UserTypeSource::Admin,
         ]);