Hello,
I have a trigger set up to run a function on “Create” with authentication. This function creates a document in my members collection to contain some basic info about the user. The function looks like this:
exports = function(authEvent){
// Only run if this event is for a newly created user.
if (authEvent.operationType !== "CREATE") { return }
// Get the internal `user` document
const { user } = authEvent;
const users = context.services.get("mongodb-atlas")
.db("MyApp")
.collection("members");
const isLinkedUser = user.identities.length > 1;
if(isLinkedUser) {
const { identities } = user;
return users.updateOne(
{ user_id: user.id },
{ $set: {
email: user.data.email
} }
)
} else {
return users.insertOne({ _id: user.id, email: user.data.email })
.catch(console.error)
}
};
This trigger works correctly if I manually create the user in the ui, but if I create it from the front end it does not fire. The user is created, but the trigger never fires. Here is the trigger:
Any ideas why it may be failing to trigger?