Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/Support/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ trait Auth

/**
* Get or make an auth instance.
* Supports single or multiple guards defined in 'google2fa.guard'.
*
* @return \Illuminate\Foundation\Application|mixed
*/
Expand All @@ -21,8 +22,19 @@ protected function getAuth()
if (is_null($this->auth)) {
$this->auth = app($this->config('auth'));

if (!empty($this->config('guard'))) {
$this->auth = app($this->config('auth'))->guard($this->config('guard'));
$guards = $this->config('guard');

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

foreach ($guards as $guard) {
if (auth()->guard($guard)->check()) {
$this->auth = auth()->guard($guard);
break;
}
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
'auth' => 'auth',

/*
* Guard.
* Guards to be checked for authentication.
* You can provide a string (e.g., 'web') or an array of guards (e.g., ['admin', 'agent']).
* The package will use the first authenticated guard it finds.
*/
'guard' => '',

Expand Down