firebase-functions: user.create function not triggered for Phone Auth

Version info

firebase-functions: 0.5.7

firebase-tools: 3.9.0

firebase-admin: 4.2.1

Test case

This is the function index.js

const functions = require('firebase-functions')
const admin = require('firebase-admin')

// Initialize Admin with configuration
admin.initializeApp(functions.config().firebase)


exports.fillInitialUserProfile = functions.auth.user().onCreate((event) => {
  const user = event.data
  const db = admin.database()

  return db.ref(`users/${user.uid}`).set({
    displayName: user.displayName || `Member (${user.phoneNumber})`,
    roles: []
  })
})

Steps to reproduce

  • Deploy the functions
  • Remove existing users in the Console so that it starts anew (like a new user being created)
  • Authenticate using Phone number and be sure that login was successful

Were you able to successfully deploy your functions?

There was no error during deployment of the functions

i  deploying functions
i  functions: ensuring necessary APIs are enabled...
i  runtimeconfig: ensuring necessary APIs are enabled...
✔  runtimeconfig: all necessary APIs are enabled
✔  functions: all necessary APIs are enabled
i  functions: preparing functions directory for uploading...
i  functions: packaged functions (931 B) for uploading
✔  functions: functions folder uploaded successfully
i  starting release process (may take several minutes)...
i  functions: updating function fillInitialUserProfile...
✔  functions[fillInitialUserProfile]: Successful update operation. 
✔  functions: all functions deployed successfully!

✔  Deploy complete!

Expected behavior

  • Logs should at least report errors if my function is doing something wrong
  • Under functions Dashboard, the executions count should be incremented to 1.
  • In the database, the users/…/* should be populated for the user

Actual behavior

  • No logs whatsoever recorded
  • Under functions Dashboard, the executions count remains 0.
  • In the database, the users/.../* is empty

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 16 (7 by maintainers)

Most upvoted comments

@rjhuijsman An onCreate event handler for custom auth tokens is definitely something I’d love to see implemented as well. I understand it’s not a simple implementation, so thanks for keeping it in mind.

I’m sorry, I can’t give you any timelines. I’ll let the team know you asked though!

Phone Auth now triggers Cloud Functions, as intended. Here’s an example of the UserRecord object (in event.data) that you might receive:

{
  "metadata": {
    "createdAt": "2017-06-01T23:01:23.000Z",
    "lastSignedInAt": "2017-06-01T23:01:23.000Z"
  },
  "phoneNumber": "+1555123456",
  "providerData": [
    {
      "providerId": "phone",
      "uid": "+1555123456"
    }
  ],
  "uid": "C6simWCCNlO3Mdyq9PYyY1O8qPJ3"
}

For TypeScript users, the catch is that the phoneNumber field isn’t in our TypeScript definition for the UserRecord yet. I’ve filed an issue to track that. In the mean time, consider getting the phone number from providerData.uid field instead.

Thanks again for the reports everyone.

Thanks so much for the feedback @eliezedeck. You are absolutely right in saying that it is better to document what is being supported and not rather than to have users spend time discovering gaps experimentally. We are sorry for the disappointment and time waste you experienced. This was not intentional, and we hope to prevent things like this from happening in the future!

@rjhuijsman Is there any ETA for trigger to work when creating user with custom token?

Ah, I’m sorry about that: we don’t yet support triggering Cloud Functions (like auth.user().onCreate) on custom tokens auth. We do want to support that in the future, but we chose to launch without it so we could already bring the other forms of Auth triggers out. The same goes for Cloud Functions responding to login using anonymous tokens, which is also a future feature.

I also just realized that our documentation on Cloud Functions for Auth is very misleading in this regard; I’ll fix that. Sorry about that!