I am facing an issue with accessing localStorage
within the store, particularly in state.
I have noticed that it is not possible to access browser methods/objects
during SSR.
Here is my attempt:
export const state = () => {
if (process.client) {
return {
isAuth: localStorage.getItem('isAuth')
}
} else {
return {
isAuth: 'SomeData'
}
}
}
The Vuex development console shows as empty, no data is displayed. However, when I try the following:
export const state = () => {
if (process.client) {
return {
isAuth: localStorage.getItem('isAuth')
}
}
}
The server works correctly and sets isAuth = 'SomeData'
, but I specifically need the "client" side functionality.
How can I successfully access localStorage
?