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

sanctum sets as default guard here \Illuminate\Auth\AuthManager::shouldUse and not resolved #456

Closed
ax-ross opened this issue Jul 29, 2023 · 1 comment

Comments

@ax-ross
Copy link

ax-ross commented Jul 29, 2023

Sanctum Version

16.1

Laravel Version

10.4.1

PHP Version

8.1.4

Database Driver & Version

No response

Description

Hi, I have same problem - #87. I found how it happens. When "auth:sanctum" declared as middleware in \Illuminate\Auth\Middleware\Authenticate::authenticate calls \Illuminate\Auth\AuthManager::shouldUse method with $name="sanctum". Then default auth guard sets as "sanctum" and getDefaultDriver return it for Auth::logout(). That is "sanctum" guard is not resolving to config(sanctum.guard) (default web in my case) and we got this exception.

To fix this we can use Auth::guard('web')->logout() and it's working perfect. But I think will be better resolve this behavior somehow.

Bad example, but demonstrates my idea: in \Illuminate\Auth\AuthManager::shouldUse add check: if ($name === 'sanctum') {"return default sanctum guard or resolve this case something else"}.

Steps To Reproduce

Create new laravel application with sanctum.
Add "auth:sanctum" middleware for some route.
Try to call Auth::logout() in this endpoint.

@crynobone
Copy link
Member

Using Auth::guard('web')->logout() is the correct approach (also suggested on the previous thread) since Sanctum as a stateless authentication guard doesn't have any session to log out from and the current behavior means that Sanctum shouldn't just logout all other guards.

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