Trigger Function //TypeError: Cannot access member 'id' of undefined

I’m trying to create a file when a User will the first time be authenticated. I use the down below function. Somehow I am getting the following error: “TypeError: Cannot access member ‘id’ of undefined”. I don’t know why I can’t access the

    exports = function(authEvent){
          const mongodb ="mongodb-atlas");
          const users = mongodb.db('data').collection('User');
          const { user } = authEvent
          const newObjcId = new BSON.ObjectId()
          const newUser = {
            _id: newObjcId,

      return users.updateOne({_id: newObjcId}, newUser, {upsert: true});

Here’s a snippet of an auth trigger I have that successfully uses – maybe copy that syntax?

exports = function({user}) {
  const db ="mongodb-atlas").db("RChat");
  const userCollection = db.collection("User");
  const partition = `user=${}`;

This was for email/password authentication when a new user registers.

What authentication and event types is your trigger running for?

1 Like

Hey, it’s an apple and google authentication event when a user authenticate the first time. It still says “TypeError: Cannot access member ‘id’ of undefined”

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.