Closed khtodod closed 2 weeks ago
You may have forgotten to add the statefulApi
middleware method in your application's bootstrap/app.php
file. This can be critical for correctly handling stateful requests.
->withMiddleware(function (Middleware $middleware) {
$middleware->statefulApi();
})
If you are still facing the issue, feel free to check out this detailed tutorial: Nuxt 3 + Laravel Sanctum Authentication Guide, where I have explained the process step-by-step.
Good luck! Let me know if you have any other questions!
Hi, I'm experiencing an issue where, after a successful login, the following request to retrieve the authenticated user returns a 401 Unauthenticated error. Below are my configurations for cors.php, .env, and nuxt.config.ts. I'd appreciate any guidance on resolving this.
Issue Details
After successfully logging in, the following request to get the authenticated user's data results in a 401 response. The cookies are present in the request headers, and the CSRF token seems to be correctly set. Here are a few additional points:
Laravel App: Running on localhost:8000 Nuxt App: Running on localhost:3000 Sanctum Configuration: Using cookie-based authentication mode. I suspect this might be related to session cookies or CSRF configuration, but I've followed the documentation as closely as possible. Do you have any suggestions on what might be causing this 401 Unauthenticated error?