diff --git a/src/Support/Auth.php b/src/Support/Auth.php index 8ef3a00..72e4901 100644 --- a/src/Support/Auth.php +++ b/src/Support/Auth.php @@ -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 */ @@ -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; + } + } } } diff --git a/src/config/config.php b/src/config/config.php index a04fefd..cf651cc 100644 --- a/src/config/config.php +++ b/src/config/config.php @@ -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' => '',