-
-
Notifications
You must be signed in to change notification settings - Fork 26
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
[Bug] When using https and the user is authenticated when refresh it gets log out #275
Comments
Hey @ezekel, do you have different URL for Laravel which is accessible by your Nuxt server app? Usually it happens if SSR and CSR call different URLs and thus cookies are not available. For more details, you can also change the sanctum module log level to 5 (you can find it in the module docs) and attach output here, it should show why your user gets unauthenticated on page refresh. |
Hi @manchenkoff , can you show me where to edit the sanctum module to level 5 ?
but why if disable ssr it will works fine ? if I refresh it will not redirect to login page if I disable the ssr. Thank you in advance. |
Please, check this link - https://manchenkoff.gitbook.io/nuxt-auth-sanctum/advanced/logging
The difference between SSR and CSR is that your Laravel API is being called from different hosts, which can cause CORS issues and may not be supported by the Laravel app if the SSR host is not included in stateful domain list. You can check more details here - https://manchenkoff.gitbook.io/nuxt-auth-sanctum/usage/cookie-authentication |
Hi @manchenkoff I don't know if I get the correct using logLevel nuxt.config.ts
I tried also to include the api to the stateful domains but no luck
I also have middleware middleware/sanctum_verified.ts
|
I saw this it looks like same problem withe me ssr enable but I tried to put this to sanctum module it doesnt work
|
@ezekel, in your case, this is a problem. Your Laravel API is not reachable from the Nuxt SSR image, probably because your Docker container is named differently. It has nothing to do with the
This is unnecessary because api.* domain is not for frontend callers. |
This is my Docker Compose setup. Actually, my container name is already set by its domain name, as it has been configured this way previously. However, I still have no luck when I enable
Running docker network ls
|
@ezekel I would recommend trying to ping the Laravel container from your Nuxt container to determine the problem (by opening a terminal session, for example). All of them should be in the same network and be available by container name as a host. |
I exec my node container and ping my laravel
|
I see, then the problem is different. Is it also available from Nuxt as https connection? You can try |
not from the browser, I meant from your Nuxt container since you have problem with SSR only |
|
@ezekel now you have the reason why SSR doesn't work, apparently your container is not available under 443 port, I am not familiar with the containers you use, but I would imagine that you have some Caddy proxy for HTTPS, which is not Laravel instance. In that case you should use |
yes I use proxy and this is my caddfile
|
I will be back I will try to fix the proxy |
So, in your case this is how Nuxt works:
|
Actually I was not able to fix this in my local machine https with ssr enable, my question if I deploy this to the server using docker does my problem will fix since it is already live server not in local? |
It depends on how you manage the network, if you have the same setup, it will be the same problem. However, if you work with a direct domain name instead of a host, it should be fine. |
Hi @manchenkoff,
I noticed an issue when using HTTPS with both Laravel and Nuxt, and setting
ssr: true
in my nuxt.config. After authenticating, if I refresh the Nuxt app, it redirects me to the login page. Additionally, if I try to directly access the URLhttps://larabells.local/dashboard
in the browser, it also redirects me to the login page.Note:
Disabling the ssr works fine
I am using frankenphp laravell 11 and nuxt3 and caddy and docker
.env
NUXT_PUBLIC_SANCTUM_BASE_URL=https://api.larabells.local
nuxt.config.ts
login.vue
dashboard.vue
see my video
nuxt-auth-1.mp4
Thank you in advance
The text was updated successfully, but these errors were encountered: