I’m trying to learn how to use Firebase with Node JS and there’s a thing I can’t understand. I’ve been looking for an explanation for a few days now, but I just can’t find something useful.
After following some tutorials, I’m confused because some of them use the serviceAccountKey file which looks like
"type": "service_account",
"project_id":
"private_key_id":
"private_key":
"client_id":
"auth_uri":
"token_uri":
"auth_provider_x509_cert_url":
"client_x509_cert_url":
and then they initialize it like this
admin.initializeApp({
credential: admin.credential.cert(credentials)
});
While others use the Firebase configuration file which is generated when you register the app on Firebase, which looks like this:
const firebaseConfig = {
apiKey:
authDomain:
projectId:
storageBucket:
messagingSenderId:
appId:
measurementId:
}
What is the difference? When are you supposed to use the first way or the second way?
If there is some documentation about this, please help me with it because I can’t find anything relevant.
>Solution :
The first one you mentioned is for backend / Admin SDK code.
The second one is for the frontend / web SDK.
These SDKs are not compatible with each other and require different ways to initialize them.