Skip to content

FirebaseGuard.php updated to use the Laravel Guard interface correctly.#20

Open
dfeneck wants to merge 1 commit intofirevel:masterfrom
dfeneck:master
Open

FirebaseGuard.php updated to use the Laravel Guard interface correctly.#20
dfeneck wants to merge 1 commit intofirevel:masterfrom
dfeneck:master

Conversation

@dfeneck
Copy link

@dfeneck dfeneck commented Oct 8, 2025

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.

  • Note: I'm unsure if these changes are Laravel 12 specific, but I am using 12 and these changes are working brilliantly for me.

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?):

$firebaseGuard = app(FirebaseGuard::class);
$user = $firebaseGuard->user($request);

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.

@sl0wik
Copy link
Collaborator

sl0wik commented Dec 9, 2025

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.

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.

2 participants