Skip to content

Commit 8ea86b8

Browse files
committed
fix: fix user resource for undefined key access_token
1 parent 034f19a commit 8ea86b8

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

app/Http/Resources/V1/Auth/UserResource.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,16 @@ public function toArray(Request $request): array
4949

5050
return array_values(array_unique($permissionSlugs));
5151
}),
52-
$this->mergeWhen(isset($this->resource->access_token), [
53-
'access_token' => $this->resource->access_token,
54-
'refresh_token' => $this->resource->refresh_token,
55-
'access_token_expires_at' => $this->resource->access_token_expires_at?->toISOString(),
56-
'refresh_token_expires_at' => $this->resource->refresh_token_expires_at?->toISOString(),
57-
'token_type' => 'Bearer',
58-
]),
52+
$this->mergeWhen(
53+
array_key_exists('access_token', $this->resource->getAttributes()),
54+
fn () => [
55+
'access_token' => $this->resource->getAttributes()['access_token'],
56+
'refresh_token' => $this->resource->getAttributes()['refresh_token'] ?? null,
57+
'access_token_expires_at' => optional($this->resource->getAttributes()['access_token_expires_at'] ?? null)?->toISOString(),
58+
'refresh_token_expires_at' => optional($this->resource->getAttributes()['refresh_token_expires_at'] ?? null)?->toISOString(),
59+
'token_type' => 'Bearer',
60+
]
61+
),
5962
];
6063
}
6164
}

0 commit comments

Comments
 (0)