honor
honor

Reputation: 8138

UNAUTHENTICATED error in firebase firestore https callable cloud functions

Recently I added a couple of new callable firebase cloud functions to my mobile app. The thins is, once I deployed and tested my functions I was not able to invoke them failing with an UNAUTHENTICATED error. I re-deployed all my functions and still, the old ones can be invoked while the new one failed with UNAUTHENTICATED. I did some research and people were talking about the version of the Node. I upgraded the Node version but it did not work out. I upgraded the firebase-functions version and the firebase-admin version. No luck.

I tried to browse to the URL of one of the older callable cloud functions that I have deployed before and it was ok. Then I tried to browse to a newly deployed https callable firebase cloud function. I saw this message in my browser:

Your client does not have permission to get URL /function_name from this server.

Any ideas what is going on here?

Thanks

Upvotes: 5

Views: 5261

Answers (3)

Mariana Reis Silveira
Mariana Reis Silveira

Reputation: 311

I was having the same problem and what worked for me, was as simple as changing the function's name in the file (and of course where it was called) and redeploying it, which automatically deleted the first one.

EDIT #1: I've just had the same problem again and this time, I didn't rename the function. I only deleted the function manually inside firebase and then I redeployed it. It also works.

EDIT #2: Once again I had the same problem. However, this time I couldn't fix it with the alternatives above. I had upgraded my firebase-tools and something on this new version (10.3.1) was conflicting. Until I figure out what is the problem, I just downgraded firebase-tools (following this: https://stackoverflow.com/a/57262942/14608654) to version 10.2.2 and the error vanished.

Upvotes: 3

Agung
Agung

Reputation: 13843

in my case, I write wrong function name in my Flutter app

final callable = _functions.httpsCallable('wrong function name in here');

Upvotes: 0

honor
honor

Reputation: 8138

Ok, here is what I found.

According to this page: https://cloud.google.com/functions/docs/securing/managing-access-iam#allowing_unauthenticated_function_invocation

As of January 15, 2020, HTTP functions require authentication by default. You can specify whether a function allows unauthenticated invocation at or after deployment.

Here is what you do:

1- Browse to the link above

2- Find "Viewing users" section and click on the "Go to Google Cloud Console" button.

enter image description here

3- On the screen that opens, you will see a list of your deployed cloud functions. Select the one that is throwing the UNAUTHENTICATED error.

Click the Add Member button that appears on the right pane.

enter image description here

4- Select Cloud Functions Invoker role

enter image description here

5- Type allusers inside the "New Members" box. Select allUsers or allAuthenticatedUsers (Try with both to see which one works for you)

enter image description here

6- Hit "Save"

You should be able to invoke your firebase https callable cloud function now, and the UNAUTHENTICATED error should be gone.

Upvotes: 10

Related Questions