0

I can not for the life of me figure out why this is complaining. I was able to make an onCall function just fine (removed it here)... but when I make a firebase auth onCreate function, the get the error beow. What am I doing wrong?

This is the only code I have in my index.js right now.

Code:

import { onRequest, onCall } from 'firebase-functions/v2/https';
import { onDocumentCreated } from 'firebase-functions/v2/firestore';
import { initializeApp } from 'firebase-admin/app';
import { getFirestore } from 'firebase-admin/firestore';
import * as functions from 'firebase-functions'; 
initializeApp();
const db = getFirestore();

export const sendWelcomeEmail = functions.auth.user().onCreate((user) => {

    console.log("123")
});

Error:

TypeError: Cannot read properties of undefined (reading 'user')

1
  • You're not importing firebase-functions correctly for auth functions. It should be import * as functions from 'firebase-functions/v1'; since auth.onCreate isn't yet supported by the v2 APIs. The other imports v2 you're showing are not relevant for an auth.onCreate type function, and if you're not using them, they should be removed. Commented Nov 18 at 21:33

1 Answer 1

0

The issue is that you're mixing Firebase Functions v1 and v2 APIs!

You're importing from firebase-functions/v2/* at the top, but then trying to use the v1 API with functions.auth.user().onCreate().

  1. Import onUserCreated from firebase-functions/v2/identity

  2. Use onUserCreated() instead of functions.auth.user().onCreate()

  3. The user data is in event.data (not passed directly as a parameter)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.