My Angular app has two functions in Firebase. One trigger(document.create), and one callable. The trigger one executes without issue. The callable one is throwing a permission issue
Error: 7 PERMISSION_DENIED: Missing or insufficient permissions
My index.ts
import * as admin from 'firebase-admin';
admin.initializeApp();
const triggerFN = require('./trigger-function');
const callableFN = require('./callable-function');
exports.triggerFN = triggerFN.triggerFN;
exports.callableFN = callableFN.callableFN;
My callable function
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
export const callableFN = functions.https.onCall(async (data, context) => {
console.log('line 1')
return admin.firestore().collection('users').where('email', '==', 'email@home.com').get()
.then((qSnap: any) => {
console.log('line 2');
// this never gets hit
return {state: 'ok'}
})
.catch(error => {
console.log(error);
return {state: 'error', details: error}
});
console.log('line 3')
} catch (error) {
console.log(error)
return {state: 'error'};
}
})
My trigger function
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
export const triggerFN = functions.firestore.document('invites/{gameId}').onCreate( async (snap, context) => {
console.log(snap.data())
try {
admin.firestore().collection('users').where('email', '==', 'email@home.com).get()
.then((qSnap: any) => {
}).catch((err: any) => {
console.error(err);
}) ;
} catch (error) {
console.log(error);
}
})
And my permissions
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth.uid != null;
}
}
}
Both of these functions work in the emulator.
The function executes, since I can log information. And it can't be the security rules, since the trigger function works without issue. It looks like the context.auth? is not being applied to the callable function.
I've tried redeploying the functions to different regions. I've tried initializing the admin with a json key.
Any suggestions would be appreciated