nuxt-auth icon indicating copy to clipboard operation
nuxt-auth copied to clipboard

fix: authState getting wiped on page reload on static websites

Open Vijayabhaskar96 opened this issue 1 year ago β€’ 11 comments

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.

Vijayabhaskar96 avatar Jul 03 '24 12:07 Vijayabhaskar96

Hello @zoey-kaiser, is there anything we can do to help get this fix shipped ?

Thanks !

Geekimo avatar Aug 07 '24 20:08 Geekimo

Hi @Geekimo πŸ‘‹

I would like to get a review by @phoenix-ru in before merging this PR 😊

zoey-kaiser avatar Aug 08 '24 18:08 zoey-kaiser

@zoey-kaiser Thanks for your reply ☺️

Geekimo avatar Aug 08 '24 19:08 Geekimo

Any news on this fix or can we help? I use a local provider and having auth work with ssg would be highly appreciated :-)

thorge avatar Aug 23 '24 12:08 thorge

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.

Geekimo avatar Sep 04 '24 06:09 Geekimo

Open in Stackblitz

npm i https://pkg.pr.new/@sidebase/nuxt-auth@785

commit: 44d1291

pkg-pr-new[bot] avatar Sep 18 '24 17:09 pkg-pr-new[bot]

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

zoey-kaiser avatar Sep 18 '24 17:09 zoey-kaiser

Hello @zoey-kaiser, will this PR be included in the next release (if yes, when is it planned ?) Regards

Geekimo avatar Oct 01 '24 19:10 Geekimo

Is there a specific reason why this wasn't included in the 0.9.4 release?

thorge avatar Oct 21 '24 16:10 thorge

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?

thorge avatar Nov 18 '24 09:11 thorge

@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

phoenix-ru avatar Nov 28 '24 17:11 phoenix-ru