fix: authState getting wiped on page reload on static websites
Previous PR: #712
π Linked issue
#551
This issue occurs because data (data from getSession()) is not stored in the browser, which is not a problem in SSR with server because the server takes care of it, but on a statically generated website, this data is lost along with rawToken even if the token is stored in the browser cookies if you refresh the webpage.
β Type of change
- [ ] π Documentation (updates to the documentation, readme or JSdoc annotations)
- [X] π Bug fix (a non-breaking change that fixes an issue)
- [ ] π Enhancement (improving an existing functionality like performance)
- [ ] β¨ New feature (a non-breaking change that adds functionality)
- [ ] π§Ή Chore (updates to the build process or auxiliary tools and libraries)
- [ ] β οΈ Breaking change (fix or feature that would cause existing functionality to change)
π Description
This PR stores the retrieved data from getSession() and stores it in the browser cookie auth:sessionCookie and reloads the data and rawToken back on the client side if they're undefined.
This PR fixes the data issue, but you still need to set the prerender:false for middleware protected routes in routeRules so that client-side middleware is forced to run and load the states.
π Checklist
- [X] I have linked an issue or discussion.
- [ ] I have added tests (if possible).
- [ ] I have updated the documentation accordingly.
Hello @zoey-kaiser, is there anything we can do to help get this fix shipped ?
Thanks !
Hi @Geekimo π
I would like to get a review by @phoenix-ru in before merging this PR π
@zoey-kaiser Thanks for your reply βΊοΈ
Any news on this fix or can we help? I use a local provider and having auth work with ssg would be highly appreciated :-)
Hello @zoey-kaiser and @phoenix-ru, Sorry to bother you about this fix, but I'm currently holding a deployment to production due to this bug. I'd really love to help you out to get this released.
Kind regards.
Hi @Vijayabhaskar96 π
I wanted to push this PR into the next release, but sadly the authjs tests are failing. We will finalize the PRs for the release tomorrow. For the case that we are not able to include it yet, you can directly install your PR as an npm package using:
pnpm add https://pkg.pr.new/@sidebase/nuxt-auth@785
Hello @zoey-kaiser, will this PR be included in the next release (if yes, when is it planned ?) Regards
Is there a specific reason why this wasn't included in the 0.9.4 release?
Sorry, I donβt want to come across as impatient, but weβre currently holding back a production site until this fix is implemented. Is there already an idea of when this will be released?
@Geekimo @thorge @Vijayabhaskar96 Hi, sorry for keeping you waiting as this PR has been quite controversial for me. I just left my concerns in the review above. I don't want to give any false promises about merging the PR soon, as I do not feel confident at all in the patch.
If you trust it, you can use it at your risk by using the latest commit (see the message from bot -> click on commit):
pnpm add https://pkg.pr.new/@sidebase/nuxt-auth@0f7e51a
I know it's one of the long-standing issues in the local provider and I will try to come back at it with a different approach within 2024.
upd: Unfortunately, I didn't have enough resources in December due to other internal company projects. I will keep this PR in priority when I come back in the second part of January