Closed simeon9696 closed 3 years ago
Hey @simeon9696 As you can read in the documentation:
This does not authenticate the Firebase Client SDK on the server. While you will be able to know if a user is logged in or not and have access to its simplified properties, you won't be able to do authenticated calls on server-side.
So you won't be able to do authenticated calls to Firestore from the server. This is due to the fact that the Firebase JS SDK is a client SDK and not made for server with multiple users.
We have an experimental workaround by using the serverLogin option, but I do not recommend it for production due to its limitations.
br, Pascal
@lupas I understand that bit now, I thought it meant I can't do any calls from nuxtServerInit
. Is there a way to force the call to happen on the client then?
@simeon9696
Yes, you can wrap your code in if (process.client)
if (process.client) {
// your code
}
or you can wrap entire components like so and make that call only in that component:
<client-only placeholder="Loading...">
<!-- this component will only be rendered on client-side -->
</client-only>
See https://nuxtjs.org/docs/2.x/features/nuxt-components/
Hope that helps.
@lupas It did run on the client but the call to firestore was still denied. I think I'm missing something. If auth ssr is enabled and I sign in with email and password, why do calls that are wrapped in process.browser
fail?
@simeon9696 Hard to tell, if you are logged in the calls should be authenticated... :/ If you could reproduce a minimal example and upload it I could have a look, there must be an issue somewhere in your code. I can't see anything in the code you posted above though... :(
I'm setting up ssr auth and even though I've successfully logged in the user, the calls to firestore still fail with:
My security rules:
Function that writes to firestore (inside of a vuex action):
And the relevant bits of nuxt.config.js
Version
@nuxtjs/firebase: 7.6.1 firebase: 8.6.7 nuxt: 2.15.6
What is Expected?
An authenticated user can make writes to Firestore if the security rules permit. In
nuxtServerInit
I do see the user information printed out so the login is successful. Just not sure why the writes still fail. Am I supposed to see two service workers running? Right now I only see 'sw.js' is running.What is actually happening?
Writes are being denied even though the user is authenticated