Ross
Ross

Reputation: 3008

How to manage user state in Firebase authentication within a SSR Nuxt.js application?

As the title suggests, how to manage the user state in Firebase authentication within an SSR Nuxt.js application? The following conditions should be met after a successful login:

Upvotes: 0

Views: 1862

Answers (1)

Ross
Ross

Reputation: 3008

I was able to solve this problem by using the following:

  • Express server - using axios posts to manage the login on receiving
    the request save the user ID in the session and save the access token in a cookie
  • Vuex - store user state so easily accessible within my Nuxt application
  • Nuxt server middleware - used to check the authentication status of the user on the server. Looking for user ID in the session or the access token in a cookie that would have been created on login

Access to the code containing a working, running example of this scenario can be found in this GitHub repository.

I have also written a more detailed blog entry regarding all the important files used in the project.

Upvotes: 4

Related Questions