Laravel API returns 401 even while logging in succeeds
For me, it turned out the
stateful property in
config/sanctum.php was not filled correctly.
After setting it to the default as shown below, it started working.
// file config/sanctum.php ... 'stateful' => explode(',', env('SANCTUM_STATEFUL_DOMAINS', sprintf( '%s%s', 'localhost,localhost:3000,127.0.0.1,127.0.0.1:8000,::1', Sanctum::currentApplicationUrlWithPort() ))), ...
Did this not fix your problem?
Check this post which might help: https://stackoverflow.com/a/69858100