0

I'm trying to use the Firebase admin auth to get users by phone number via cloud function. Here is the cloud function (minus some request body validation).

module.exports = (req, res) => {
  const phone = req.body.phone;

  admin.auth().getUserByPhoneNumber(phone).then(userRecord => {
    res.send({ user: userRecord });
  })
  .catch(getUserErr => {
    res.status(422).send({ error: getUserErr });
  });
};

where phone is E.164 compliant. I'm getting the following error in the response:

Error: could not handle the request

A couple important pieces of information. I'm calling this from a cloud function. Also, I'm currently creating anonymous users with phone numbers (via a different cloud function), not using the phone sign-in provider.

admin.auth().createUser({
  phoneNumber: phone
})

I tried turning on the phone auth provider (in addition to the anonymous sign-in provider), but that doesn't seem to matter.

Anyone know what would cause this? The docs are silent on any other setup that's necessary.

Paul
  • 420
  • 4
  • 16
  • Could you share the full implementation of your function? Or at least the part that calls the above method? – Hiranya Jayathilaka Nov 10 '17 at 19:06
  • Edited question to include full function. I would think if the function couldn't find a record, it would do the same as getUser and getUserByEmail and return an error like: { "error": { "code": "auth/user-not-found", "message": "There is no user record corresponding to the provided identifier." } } – Paul Nov 11 '17 at 00:58
  • 1
    Yes. This is actually not an error raised by the admin SDK. Something else is failing here. See https://stackoverflow.com/questions/45600367/cloud-functions-for-firebase-error-could-not-handle-the-request for some helpful ideas in debugging this. – Hiranya Jayathilaka Nov 11 '17 at 01:15

1 Answers1

0

Update firebase-admin package. getUserByPhoneNumber isn't available until version v5.1.0

Paul
  • 420
  • 4
  • 16