Open rel0aded opened 5 years ago
This may be a bug in Wildside\Userstamps instead, if it's decided that auth()->id() is working as intended here.
I have temporarily resolved this in my code by overriding each model's registerListeners() method, and using my own Listener methods to return auth() ->user() -> id
instead.
I still think this is a bug in jwt-auth though, I can see other libraries using the same call, presuming it to be the model's primaryKey. However, I am happy to raise a bug report there instead, once I have a definite answer this is intended behaviour.
I have to no problems. I use Laravel Framework 5.8.35
Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Subject of the issue
When using the JWTAuth guard
auth()->id()
(which is used by various packages, such as wildside\userstamps when setting the created_by field in https://github.com/WildSideUK/Laravel-Userstamps/blob/master/src/Listeners/Creating.php) return the value set in the 'sub' attribute of the JWT rather than model's primaryKey.This breaks using an incremental 'id' value as the server-side primary key, cross-referenced as the foreign key on other tables, but also using a public facing UUID value in the JWT.
Your environment
Steps to reproduce
Create a model with both
id
anduuid
attributes. Keepprotected $primaryKey = 'id';
Add three methods to the User model:
Issue a valid JWT token for the user, and execute the following closure
Behaviour
I'd expect
auth()->id()
to be 1 (the primaryKey of User); instead I get the UUID of the user back.dd(auth()->id());
"00000000-0000-0000-0000-000000000000"dd(Auth::id());
"00000000-0000-0000-0000-000000000000"dd(Auth::user()->id);
1dd(Auth::user()->getKey());
1