Hi someone know how can I save the state of redux ...
# orm-help
a
Hi someone know how can I save the state of redux in the localstorage on nextjs?
l
Join the spectrum community of Next.js here: https://spectrum.chat/next-js
Having that said, it's not recommended to store the state of redux in localStorage if you're using Next.js
SSR will not work because there's no browser instance (which means no localStorage).
a
@lfades so what solution do you recommend?
And thanks for the link!
l
If you only need to save a few amount of data, use cookies
for some cases using a database may also be a good solution
and if you really need to store the redux store in localStorage, then you'll need to drop SSR
which makes Next.js very pointless for that case
a
@lfades I'm using the redux state to check if a user is authenticated or not... (The back works with express-session) so, what I do, I always execute one query, and through redux that state help me to check that user... But when I reload the page, that state disappear... :( I don't know how to resolve it
l
You don't need localstorage just use cookies
h
The firebase approach is an object stored in localstorage/indexeddb and a function that triggers to check if the object exists or not
Could implement that on _app
a
@HarryC do you have some example m
?
h
I haven't directly implemented it, I use firebase auth myself
This way every time an SSR happens, the _app can do something like
firebase.auth().onAuthStateChanged((user)
to check if the user is logged in or not