nuxt-auth
nuxt-auth copied to clipboard
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.