Skip to content

Commit

Permalink
Support multiple guards for SPA
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenbdf committed Jan 21, 2021
1 parent 4961787 commit f902d9f
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/Guard.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,18 @@ public function __construct(AuthFactory $auth, $expiration = null, $provider = n
*/
public function __invoke(Request $request)
{
if ($user = $this->auth->guard(config('sanctum.guard', 'web'))->user()) {
return $this->supportsTokens($user)
? $user->withAccessToken(new TransientToken)
: $user;
$guards = array_keys(config('auth.guards'));

if (empty($guards)) {
$guards = [null];
}

foreach ($guards as $guard) {
if ($user = $this->auth->guard($guard)->user()) {
return $this->supportsTokens($user)
? $user->withAccessToken(new TransientToken)
: $user;
}
}

if ($token = $request->bearerToken()) {
Expand Down

0 comments on commit f902d9f

Please sign in to comment.