FirebaseGuard.php updated to use the Laravel Guard interface correctly.#20
Open
dfeneck wants to merge 1 commit intofirevel:masterfrom
Open
FirebaseGuard.php updated to use the Laravel Guard interface correctly.#20dfeneck wants to merge 1 commit intofirevel:masterfrom
dfeneck wants to merge 1 commit intofirevel:masterfrom
Conversation
Collaborator
|
Thank you for your contribution, and sorry it took so long. I should be able to merge it after pushing a solid set of tests with different Laravel versions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
I've had a few issues while attempting to use this, so I've made some small changes to bring it inline with what Laravel is expecting a Guard to be. Please let me know if you have any questions.
Summary
1) Converts FirebaseGuard into a full Illuminate\Contracts\Auth\Guard implementation.
The original FirebaseGuard wasn’t registered with Laravel’s Auth system. It was just a plain helper class, not a real “guard” — so when something called:
$user = Auth::guard('api')->user();Laravel’s AuthManager didn’t know about Firevel’s guard at all. It was using the default null driver — which always returns null.This change ensures the FirebaseGuard is binded to the \Auth object. Syntax like
\Auth::id();and$user = Auth::user();can now be used project wide, or the original firebase class can be used directly still for legacy use (I'm assuming this is what people were doing to fetch the user before this change?):Which means you can now set authorised only routes with middleare(['auth:api']), or create your own middleware which can simply attempt to fetch the user and implement your own logic (such as not return unauthorised when no user for an optional route).
2) Fixes user(Request $request) signature mismatch with Laravel’s expected user() & Adds missing methods (check, guest, id, hasUser, validate, setUser).
These are only required to satisfy the Guard interface and work exactly as expected. No functionality change here.
3) Maintains backward compatibility for direct $firebaseGuard->user() calls.
This should ensure people updating shouldn't experience any issues.