Support multiple guards #207
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request improves the guard resolution logic in the
getAuth()
method to support both single and multiple authentication guards as defined in the google2fa.guard configuration setting.Previously, only a single guard could be used by specifying a string (e.g., 'web') in the config, and the code would directly call
auth()->guard($guard)
. Now, the logic supports both a string or an array of guards (e.g., ['admin', 'agent']).When multiple guards are provided, the method will loop through each guard and assign
$this->auth
to the first one that has an authenticated user (i.e.,auth()->guard($guard)->check()
returns true).With this update, if a user is logged in under any of the specified guards, the package will automatically detect and use the correct guard. This greatly improves compatibility with multi-auth applications where users may belong to different guards such as admin, agent, or customer.
This change ensures that the correct authenticated context is selected without requiring developers to hard-code a specific guard or duplicate logic in their application.
Sample Issues Resolved by This Pull Request:
#103 , #90