I am using Firebase and Cloud Firestore to build a group app, where users should be able to create groups and add members to it.
As a user creates a group, I want a cloud trigger to add that user to the group's member list after the group has been created. The trigger looks like this:
exports.addCreatorAsAdmin = firestore
.document('groups/{group}')
.onCreate((snap, context) => {
if (context.auth == null) { return unauthorizedError() }
const path = `groups/${context.params.group}/members/${context.auth.uid}`;
return db.doc(path).create({});
});
As I run the app, sign in the user and create a team, the function is correctly triggered. However, I always hit the unauthorized error, which means that context.auth is null.
TLDR; the user is correctly signed in, but the trigger is unauthorized. Can anyone help me out?