-
-
Notifications
You must be signed in to change notification settings - Fork 15
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
Losing Authenticated State on Page Refresh #6
Comments
Hey @J0Sepff, error is not related to the package since I do not use pinia, probably you forgot to exclude reactive values with localStorage during the hydration by using In the meantime, I will try to setup a playground without SSR to make sure that authentication state stays the same after reload. |
@manchenkoff Thanks for the answer. You're right, the mistake with SSR is on my side. Authorization is saved if I use SSR, but if SSR: false, then authorization losing after refreshing the page. If necessary, we can contact you and show you a demo. |
Published new v0.0.11 version, @J0Sepff please try with this one, hope problem is solved |
@manchenkoff Problem solved! Thank you! |
I'm still having this issue where if you login and go to a guarded page, then refresh the page, it will show you the login prompt briefly before refreshing. I am hosting this on Cloudflare Pages and have https://nuxt.likewizard.com/ |
I think specifically this is an issue with Nuxt + Cloudflare Pages hosting. I hosted the same repo on Digital Ocean App Services, and there is no issue with the login state. So makes me think it is some sort of rendering / environment issue with that hosting provider. |
I realise this is an old issue but wanted to share my experience with this (which I'm certain is related). From what I can figure out is that the Cloudflare workers disable the What led me there was checking the server logs on nuxt admin and seeing:
I tested this theory out by hosting on Vercel and everything worked straight away. |
Thanks @alecritson for the insight! I think it might save someone's day 😄 |
Ok so just to follow up, I found this thread here: sindresorhus/ky#366 which mentions about setting credentials to I'm not a JS expert by any stretch but would something like this even work? (just copying from the PR related to that issue) const isCredentialsSupported = 'credentials' in Request.prototype;
await $fetch(config.endpoints.csrf, {
baseURL: config.baseUrl,
credentials: isCredentialsSupported ? 'include' : undefined,
}); I was trying to test myself with yarn link but I couldn't get it to play ball 😅 |
@alecritson I'm not sure either 😄 For sure I can test a positive case, but I would need someone's help with testing it in the actual environment like Cloudflare. Just in case, will you be up for that? |
That'd be awesome if you could, I have Cloudflare pages all set up and ready to give it a spin 🙏 |
Awesome, thanks! I'll try to open a PR in a next couple of days 👍 |
Hey @alecritson, published new 0.4.1 version, please try it in your app |
Thanks @manchenkoff I had a little play and it certainly stopped the issue from coming up but I think it creates a new 🤔 I tested on a Vercel deployment and Cloudflare. Same app, same domains, just switching the DNS out in Cloudflare. Cloudflare now it doesn't set the cookies on page load, I assume because their workers don't support it so they don't get set on the server request. Going to login, even though the Vercel does set them on page load and login works as expected, however, if I remove the cookies after the page load and go to login the same issue arises as Cloudflare. Could it be that even though it's calling |
Usually, it happens due to cookie domain misconfiguration between CSR/SSR/Laravel. Could you please double-check that the cookie domain is in a format like
Yes, especially when the domain is different. For example, if a cookie is set for domain |
I see, thanks for the explanation @alecritson. In this case I assume manual deletion somehow interferes with Nuxt Except this, does it work fine with page refresh and all other things? |
Yeah I'm not too sure because because in Cloudflare's instance the cookies are never set on page load due to credentials being disabled and it suffers from the same issue as the Vercel app. So it seems if the cookies aren't set then on page load they never go into subsequent requests even though they do get set in the browser. But when the page is refreshed the cookies are overwritten and the app starts working as expected. Once logged in though everything is perfect. |
Okay, I'll work on that. Thanks a lot @alecritson for your help with the debugging, I'll let you know if I find some solution to this. |
Hello! I'm using the latest version of nuxt-auth-sanctum, but the problem of losing authorization when refreshing the page persists.
Nuxt config:
Nuxt ENV:
Laravel ENV:
If I turn on SSR, the following error appears:
The text was updated successfully, but these errors were encountered: