In firebase callable functions we get a handy context parameter which includes the auth data, including the uid. I have my firestore rules properly defined, which work based on the logged in user. Is there a way to use this context to write from the server as if it were the user, so the rules apply?
A simple example:
export const firestoreCreateDocumentOnCall = functions
.region(...regions).https.onCall(async (data, context) => {
try {
const path = data.path as string;
const docData = data.data as any;
// ! This writes as admin, I would like as if it were the user provided by context !
await admin.firestore().doc(path).set(docData);
return;
} catch(error) {
console.error(`Error: ${error}`);
return { error };
}
});