[SSR] Accessing res.locals.user always returns null at nuxtServerInit
See original GitHub issueFirst, 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
innuxt.config.js
, includingcredential
and a bigsessionLifetime
value. - 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.signInWithEmailAndPassword
and receive user data. TheonAuthStateChanged
is successfully called on any client-side operation I realize with the auth. - Inspired on #69, I implemented
watcher
to look atauthUser
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 haveres.locals.user
whennuxtServerInit
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.
Issue Analytics
- State:
- Created 3 years ago
- Comments:37 (22 by maintainers)
Top Results From Across the Web
Nuxt SSR Firebase -> Permission denied - Stack Overflow
I have successfully set up the way to dispatch onAuthStateChanged on nuxtServerInit. It seems to work as res.locals.user - object contains ...
Read more >Creating Server-side Rendered Vue.js Apps Using Nuxt.js
When you initially access the site, you want to authenticate that token against an API, which returns some basic user info if valid...
Read more >@nuxtjs/firebase social auth - DEV Community
This tutorial allow you to have the user data on server side, but won't allow you to do authentified calls to firebase (such...
Read more >Firebase Auth with SSR
Reason for this is that the Firebase JS SDK is a client-side library that is ... now access the authUser under the res.locals.user...
Read more >res.locals Property in Express.js - Tutorialspoint
res.locals Property in Express.js - The res.locals is an object that contains the local variables for the response which are scoped to the ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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!
Do you have a solution for this? Apparently if you have a security rule, you will get insufficient permissions. Here’s a sample rule to get insufficient permissions:
but when you do
allow read, write: if true;
, the error is gone.