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
ssrinnuxt.config.js, includingcredentialand a bigsessionLifetimevalue. - I setup my action
onAuthStateChanged, mynuxtServerInit, and of course all the other related Vuex things, following the online demo repo. - I can successfully invoke
this.$fireAuth.signInWithEmailAndPasswordand receive user data. TheonAuthStateChangedis successfully called on any client-side operation I realize with the auth. - Inspired on #69, I implemented
watcherto look atauthUserand 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 haveres.locals.userwhennuxtServerInitis called,store.state.authUseris 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)
@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!