Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

395
Views
How can I create a logging function in firebase for auth.user().onCreate() trigger?

I am trying to log each time an account is created and deleted.

I created a trigger functions.auth.user().onCreate() and as I understand it returns an user object as in the docs: here, and here.

The functions deploy without trouble but when the trigger is called it throws an error:

Error: Process exited with code 16
at process.<anonymous> (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/invoker.js:92:22)
at process.emit (events.js:314:20)
at process.EventEmitter.emit (domain.js:483:12)
at process.exit (internal/process/per_thread.js:168:15)
at sendCrashResponse (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/logger.js:44:9)
at process.<anonymous> (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/invoker.js:88:44)
at process.emit (events.js:314:20)
at process.EventEmitter.emit (domain.js:483:12)
at processPromiseRejections (internal/process/promises.js:209:33)
at processTicksAndRejections (internal/process/task_queues.js:98:32) 

Error which I cannot understand.

Here is my code

// functions/index.js    
const functions = require('firebase-functions')
const admin = require('firebase-admin')
const { google } = require('googleapis')
const { firestore } = require("firebase-admin");

exports.logging = require('./logging');

admin.initializeApp()
// And other working functions

The actual functions

    // functions/logging.js

const functions = require('firebase-functions');
const admin = require('firebase-admin');
const { firestore } = require('firebase-admin');

const authUserTrigger = functions.auth.user()

exports.userSignup = authUserTrigger.onCreate((user) => {
  storeUser(user)
})

exports.userDelete = authUserTrigger.onDelete((user) => {
  storeUser(user)
})

    async function storeUser(user) {
      // functions.logger.log(user.email) -> this works

      // Destructured original object
      let updatedUser = (({ displayName, email }) => ({ displayName, email }))(user);
      functions.logger.log('updatedUser', updatedUser )
      await admin
        .firestore()
        .collection('logs')
        .doc('users')
        .collection('signup')
        .set({
          user: {updatedUser}, // I think this is the culprint
          // user,  This doesn't work either
          createTimestamp: firestore.FieldValue.serverTimestamp()
        }, { merge: true })
    
    };

Thank you in advance

EDIT ========== @Tanay was right. Needed to change set to add.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

As @Tanay stated, you cannot use set() in a collection in Firebase, it must be a document. If you want to add a document to the collection with an auto ID then you can use add() on the collection with the data.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!