Home > Enterprise >  Firebase Functions Exception "unauthenticated" but function does run
Firebase Functions Exception "unauthenticated" but function does run

Time:01-26

I am implementing Facebook Sign In with Firebase in my Flutter App, and when a user signs in with Facebook Sign In for the first time I am changing the "emailverified" property to true. I do this through functions with the following code:

if (facebookUser.user?.emailVerified == false) {
        try {
   HttpsCallable callable =     FirebaseFunctions.instance.httpsCallable('verifyFacebook');
          await callable.call();
        } on FirebaseFunctionsException catch (e) {
          print(e.code);
          print(e.plugin);
          print(e.message);
        }
      }

where verifyFacebook is:

exports.verifyFacebook = functions.auth.user().onCreate(async (snap) => {
  return await admin.auth().updateUser(snap.uid, {
    emailVerified: true
  });
})

What I do not understand is that a Firebase Function Exception of "unauthenticated" is printed in the console, but when I sign in for the second time the "emailverified" property is changed to true (meaning that the Firebase Function was executed properly)! How could this happen if in the try-catch part I was thrown an error?

I searched for other answers such as adding a permission in Google Cloud Console but none helped me :(

Thanks in advance!

In Google Cloud Console I added "allUsers" in the Permission property, and I expected my app to work fine without the "unauthenticated" error. However, the issue persisted.

CodePudding user response:

The verifyFacebook function triggers every time a user is created with Firebase Authentication and is not a callable function. You don't have to call the function yourself.
When you try to call it, the callable function does not exists and hence you get an error but the function triggered by Firebase Auth does run.

  • Related