Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

394
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda