firebase-module: [SSR] Accessing res.locals.user always returns null at nuxtServerInit

First, congratulations for this nice module with a bunch of options. But…

I’m facing serious problems with Firebase Auth and SSR. Even after following each part of the the SSR tutorial, my nuxtServerInit always has res.locals.user empty.

What I’ve done:

  • I installed all dependencies, including @nuxtjs/pwa.
  • I enabled ssr in nuxt.config.js, including credential and a big sessionLifetime value.
  • I setup my action onAuthStateChanged, my nuxtServerInit, and of course all the other related Vuex things, following the online demo repo.
  • I can successfully invoke this.$fireAuth.signInWithEmailAndPassword and receive user data. The onAuthStateChanged is successfully called on any client-side operation I realize with the auth.
  • Inspired on #69, I implemented watcher to look at authUser and perform route redirection when needed, but it just redirects in client-side, causing my server incorrectly redirecting / to /login, and the client back to / after a while. The login page even appears to the user before redirection with this approach!
  • I also have middlewares using store.state.authUser, but they are called only on server for the first request… And since the server don’t have res.locals.user when nuxtServerInit is called, store.state.authUser is always empty on server.

So, after all day struggling with it I’m giving up and asking for help! I can invite to take a look at my repo if needed, I just can’t make it public right now.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 37 (22 by maintainers)

Most upvoted comments

@lupas I got it working on Heroku! Running into some other deployment issues with Firebase right now but as long as you make sure you copy over the contents of the static folder into the public folder I think it should be working just fine. Thanks for your help!