Skip to content

Support multiple guards#207

Open
abdelhady-tk wants to merge 1 commit intoantonioribeiro:masterfrom
abdelhady-tk:feature/multi-guard-support
Open

Support multiple guards#207
abdelhady-tk wants to merge 1 commit intoantonioribeiro:masterfrom
abdelhady-tk:feature/multi-guard-support

Conversation

@abdelhady-tk
Copy link
Copy Markdown

@abdelhady-tk abdelhady-tk commented Jul 29, 2025

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

@abdelhady-tk
Copy link
Copy Markdown
Author

abdelhady-tk commented Jul 30, 2025

Hi @antonioribeiro,
I hope you're doing well. When you have a moment, would you mind reviewing this pull request? It adds support for multiple authentication guards and helps resolve issues #103 and #90.

Thank you in advance for your time and consideration

tkikuchi2000 pushed a commit to tkikuchi2000/google2fa-laravel that referenced this pull request Aug 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant