My goal is to save an authenticated user to local storage and then load them into Vuex on the next page load.
created () {
let user = window.localStorage.getItem('user')
if(user) {
this.setUser(JSON.parse(user))
}
}
I initially believed that placing this logic in the created hook of my root component would be appropriate. However, I encountered the error 'window is not defined'.
After trying different approaches, I found that placing it in the mounted hook resolved the issue. Although, this did result in a brief display of the login page before loading the user information.
The question remains: where is the best location to put this logic?