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 7 months ago โ€ข 8 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