I am using firebase emulator suite to test my app. I have set up emulators for hosting, authentication, firebase and functions.
When I try to create a user from front-end using firebase.auth().createUserWithEmailAndPassword() it works fine.
All other emulators work as expected too..
I am able to call a callable function from my front-end:
in public/app.js
const createUser = functions.httpsCallable('createUser');
createUser({
username: username,
email: email,
password: password,
})
in functions/index.js
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.createUser = functions.https.onCall((data, context) => {
// creates a new user
return admin.auth().createUser({
email: data.email,
emailVerified: false,
password: data.password,
displayName: data.username,
disabled: false
});
});
This function gets called, however it does not create a user on the auth emulator, but in production.
I want my user to be created on the auth emulator, so that it can trigger auth functions in my functions/index.js
For example:
exports.userCreated = functions.auth.user().onCreate(user => {
// creates a firestore document in users collection
return admin.firestore().collection('users').doc(user.uid).set({
email: user.displayName
});
});
There does not seem to be anything about connecting Node.js Firebase SDK to the auth emulator (admin.auth().useEmulator() is not defined).
How do I go about instructing a Node Admin SDK to use local auth emulator?
I followed @Vazgen answer, and I can confirm that update the firebase-admin to the latest version can fix it, version 9.9.0 as of this writing.
npm install firebase-admin@latest