I have initialised my firebase app as follows.
const PRODUCTION = false;
let firebaseConfig = {
apiKey,
...
};
// Initialize Firebase
// Check if any Firebase apps exist
const apps = getApps();
// Initialize only if no apps exist
const app = !apps.length ? initializeApp(firebaseConfig) : apps[0];
export const auth = getAuth(app);
const firestore = getFirestore(app);
if(!PRODUCTION){
connectAuthEmulator(auth, "http://localhost:9099");
connectFirestoreEmulator(firestore, "localhost", 8080);
}
This works great, but I then get a warning saying don’t use production credentials when using emulators. I think that is what I am doing though.
What is the correct way to initialise firebase with emulators?
Unsure what the best practice is in this situation.
2
Answers
The warning you are getting is issued by the Firebase Authentication Emulator when it is initialised.
Traffic to and from the Authentication emulator is not encrypted.
This means that if you have registered a user to your live application, such as an admin user, you should not use that same username and password when interacting with the emulator.
This is what it means by "do not use production credentials" – do not use credentials that are used by accounts of your actual application.
I tend to insert
+emulator
into the email address of addresses I use with the emulator to make it clear that the account does not match a production one. e.g. Instead of[email protected]
, I would use[email protected]
with a different password. Most modern email services support sub addressing like this which means you can still receive any emails sent to those accounts.We should avoid using production cred. When using firebase emulators, there is no need of production specific configuration.