manchenkoff / nuxt-auth-sanctum

Nuxt module for Laravel Sanctum authentication
https://manchenkoff.gitbook.io/nuxt-auth-sanctum/
MIT License
173 stars 21 forks source link

[Question] Not saving the token in the cookie, in token mode ("message":"Unauthenticated.") #149

Closed eduardojsc18 closed 2 months ago

eduardojsc18 commented 3 months ago

Describe the bug Good morning! I'm having a problem with the option to save my authentication token in a cookie. My back-end returns exactly as it is in the documentation (a simple JSON containing only the token {token: }) but it does not save it in the cookie, so, after returning the token, the application tries to connect to the USER but as unauthenticated. BUT if I put the save settings via localstorage in app.config it works perfectly

Expected behavior I need you to save the token in cookies

Screenshots image image

Module information

"nuxt-auth-sanctum": "^0.4.8", image

Nuxt environment:

"nuxt": "^3.12.4", Mode: CSR Environment: local

manchenkoff commented 3 months ago

Hey @eduardojsc18, I tried to reproduce the behavior but had no success. I pushed minimal repro for breeze-nuxt template, could you please try it with your API?

The branch name is token-mode, here you can find the diff.

On the API side, I have excluded localhost from SANCTUM_STATEFUL_DOMAINS and used authentication endpoints from routes/api.php instead of routes/web.php. You can check it as well, here - breeze-api.

manchenkoff commented 2 months ago

I'm closing this one due to inactivity, feel free to re-open with further details!

eduardojsc18 commented 2 months ago

Hello @manchenkoff, thank you very much for your feedback!

I did as you advised and it really worked! After removing the localhost addresses from SANCTUM_STATEFUL_DOMAINS it started saving automatically.