6
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.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Kid
  • 1,160
  • 2
  • 14
  • 31

3 Answers3

6

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.

Sushan Sapaliga
  • 324
  • 5
  • 14
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • So this means it is still in progress now? I always have to deploy these functions in order to test properly? I dont want to input test data to the function. – Kid Jul 05 '20 at 01:54
  • 3
    You can publish on another "dev" FB project (you need to create two FB projects), also you can simply run the emulator without the "auth" keyword in the command line, run all emulators using `NODE_ENV=development firebase emulators:start --inspect-functions` – David DIVERRES Jul 05 '20 at 10:34
2

firebase recently released the Authentication Emulator, you can check it via the release notes here: https://firebase.google.com/support/releases#october_26_2020, and further guide here: https://firebase.google.com/docs/emulator-suite/connect_auth

favs
  • 21
  • 1
0

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));
Kid
  • 1,160
  • 2
  • 14
  • 31