Answer the question
In order to leave comments, you need to log in
How to check if a user is logged in when using laravel sanctum?
The problem is that when using the standard Auth::check() construct, false is always returned. As I understand it, this is due to the fact that sanctum reads the token only when middleware is hung on the route. But I need the user to be not authorized, depending on this, I perform different actions
Answer the question
In order to leave comments, you need to log in
As it turned out, I just poorly configured the application. The fact is that in config/auth.php it is necessary to set the default authorization method to api, and the verification driver to sanctum
'defaults' => [
'guard' => 'api',
'passwords' => 'users',
],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'sanctum',
'provider' => 'users',
'hash' => true,
],
],
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question