Custom JWT Trigger function not working

There doesn’t seems to be anyway to test authEvents but anyway, the same provided code works on fb login and email/password trigger.

However, when you use custom JWT token, the trigger gets called (as reflected in the stitch app log), but it doesn’t insert data into collection. It doesn’t create a new document at all.

    exports = function(authEvent){

      if (authEvent.operationType !== "CREATE") { return }
      const { user } = authEvent;

      const users = context.services.get("atlas")
        .db("database")
        .collection("collection");
     const isLinkedUser = user.identities.length > 1;
      if(isLinkedUser) {
        const { identities } = user;
        return users.updateOne(
          { id: user.id },
          { $set: { identities } }
        )
      } else {
          return users.insertOne({ _id: user.id, ...user })
         .catch(console.error)
      }
    };

Hi Dave – If you DM me a link to your Atlas group I can take a closer look. Would you mind logging/posting the authEvent that’s being sent to the Trigger in the case that you describe? That might help troubleshoot the behavior you’re seeing.

1 Like

Was there any resolution to this? I am having a similar issue but when I try console.log anything nothing appears in my logs list so I am having troubles debugging.