Running the custom user creation function throws $undefined: true in console

Hi,

So I have this flutter app with realm that uses flexible sync configuration. So I wanted to implement custom user metadata apart from builtin-auths so on trying to create the onUserCreation function (code below) and running it, it throws $undefined: true in the console. What does it mean? Can anyone guide as to how can I setup my custom user creation function?

exports = async (user) => {
  const collection = context.services
    .get("mongodb-atlas")
    .db("todo")
    .collection("users");
    
  try {
    const newUser = await collection.insertOne({
      owner_id: user.id,
      avatar: user.data.avatar,
      name: user.data.name,
      isProUser: user.data.isProUser,
      token: user.token,
    });
    return newUser;
  } catch (e) {
    console.error(`Failed to create custom user data document for user:${user.id}`);
    console.error(e);
    // throw e
  }
};