Firebase test auth cloud functions locally

Viewed 2418
exports.sendWelcomeEmail = functions.auth.user().onCreate((user) => {
  console.log(user.uid);
  console.log(user.email);
  console.log(user.displayName);
});

exports.getUserInfo = functions.https.onCall(async (data, context) => {
  // get array of user IDs and returns information (from Users collection)
  const userIDs = data.userIDs;
  const result = [];
  const querySnapData = await admin.firestore().collection("Users").get();
  querySnapData.forEach((ele) => {
    if (userIDs.indexOf(ele.id) !== -1 && ele.id !== context.auth.uid) {
      result.push(ele.data());
    }
  });
  return { res: result };
});

I've got these two functions in my project - one is callable function and the other one is auth trigger functions.

So in my client app, I run

firebase.functions().useFunctionsEmulator('http://localhost:5001');

let getUserInfo = functions.httpsCallable('getUserInfo');
getUserInfo({userIDs: data}).then(res => doSomething);

And to run the cloud functions locally

firebase emulators:start

But it says

functions[sendWelcomeEmail]: function ignored because the auth emulator does not exist or is not running.

So in the client App, getUserInfo works pretty well but can't trigger onCreate.

But I was not able to find any document about auth emulator.

Any link/article/video or answer is appreciated.

3 Answers

The Firebase Emulator Suite currently Cloud Firestore, Realtime Database, Cloud Functions, and Cloud Pub/Sub. It does not yet emulate Firebase Authentication APIs. So any auth calls you make will be executed against the real project that is associated with the emulators.

This also means that your functions.auth.user().onCreate((user) => { Cloud Function will not be triggered in the emulators at the moment. You'll have to deploy it to the servers to test this trigger.

To learn when an auth emulator is available, I recommend keeping an eye on Firebase's release notes, and on the main documentation page for the emulator suite that lists the supported products. You can also follow along more closely on Github, either in the commits, or in this feature request.

So as @Franek van Puffelen wrote above, it is not done yet.

Was able to test auth functions locally like below.

function sendWelcomeEmail(user) {
  console.log(user.uid);
  console.log(user.email);
  console.log(user.displayName);
}

exports.sendWelcomeEmail = functions.auth.user().onCreate((user) => sendWelcomeEmail(user));
Related