Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with sanctum token authentication #4

Closed
thomasakarlsen opened this issue Oct 25, 2024 · 2 comments
Closed

Issues with sanctum token authentication #4

thomasakarlsen opened this issue Oct 25, 2024 · 2 comments

Comments

@thomasakarlsen
Copy link
Contributor

I am having an issue with sanctum token authentication and this package.
In my controller I was trying to get the current_login from the user, but it was always null.
The controller is behind the auth:sanctum middleware, and the user is available in the controller.

Digging through the chain of events it seems like the issue lies with Auth::user() (in CurrentLogin.php) being null when the TokenAuthenticated event is being issued by sanctum.

@thomasakarlsen
Copy link
Contributor Author

In my efforts to find a workaround for this I decided to add a middleware to perform early authentication using Auth::setUser(Auth::guard('sanctum')->user());. The added benefit of this route is having the user available on routes that not behind the auth:sanctum middleware too.
This workaround however gave me a different issue, which I belive to just be a typo in CurrentLogin.php.
Instead of being $this->logins() I belive this line should be Auth::user()->logins(), like the rest of the file.

$this->currentLogin = $this->logins()

Modifying CurrentLogin.php gives me a fully working setup where I have the user available early, even in middlewares, and with the correct login session available on current_login.

@alajusticia
Copy link
Owner

Thanks for reporting this issue!
The current login is now based on the authenticatable model from the Authenticated and TokenAuthenticated events.

Fixed in v1.2.5

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

No branches or pull requests

2 participants