0

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 Firebase Cloud Functions Firestore Trigger produces: Error: 7 PERMISSION_DENIED: Missing or insufficient permissions

I've tried redeploying the functions to different regions. I've tried initializing the admin with a json key.

Any suggestions would be appreciated

Screen cap of log

  • How are you calling the callableFN? – JayCodist Nov 03 '20 at 15:30
  • What exactly do you see in the functions log in the Firebase console? – Doug Stevenson Nov 03 '20 at 16:06
  • Is it normal that you assign the `onCreate` background triggered cloud Function to `const callableFN` or it is a typo in your question? – Renaud Tarnec Nov 03 '20 at 17:26
  • @JayCodist I'm calling in from an Angular component (sorry for the formatting) `const newgame = firebase.functions().httpsCallable('callableFN'); newgame({payloadData: SOMEDATA}}) .then((resp) => { resp.data.state === 'ok' ? this.router.navigate(['account']) : window.alert('Something went wrong. We could not create the game. Please try again'); });` – Lee Christensen Nov 03 '20 at 19:03
  • @RenaudTarnec you are correct. There was a small copy/pasted error in the code I posted. I have edited that piece. – Lee Christensen Nov 03 '20 at 19:05
  • @DougStevenson I've edited the post to provide a screen cap of the logs. As an aside, anyone who can explain how to get the log details on a single line would have my gratitude! – Lee Christensen Nov 03 '20 at 19:09
  • Make sure that the service account has the required role (the App Engine default service account requires the `Editor` role). – fractalix Nov 05 '20 at 05:31
  • Lee: Did the last comment help you? – MrTech Nov 12 '20 at 19:31
  • @MrTech It did not. I ended up creating another db – Lee Christensen Nov 13 '20 at 20:07
  • Lee: Please let us know if you still have that original issue. – MrTech Nov 13 '20 at 20:37
  • @MrTech As far as I know the problem still exists. I had to switch Firebase projects in order to resolve the problem. – Lee Christensen Nov 18 '20 at 16:01
  • Lee: You may choose to submit a bug report if you wish (https://firebase.google.com/support/troubleshooter/report/bugs). – MrTech Nov 18 '20 at 17:55

0 Answers0