I have integrated Firebase into my React Native app, and I have only enabled anonymous login feature.
Currently, I am attempting to invoke a Cloud Function
from the app without utilizing the firebase
SDK. Instead, I intend to make the call using axios
. Despite passing the token obtained from my firebase
user as a Bearer token, I receive a 401 Unauthorized error.
Interestingly, the request is successful when I manually copy the token generated by running gcloud auth print-identity-token
in the CLI.
How can I generate/set up a valid token that can be passed to the Cloud Function? Any relevant documentation on this topic would be greatly appreciated.
I am trying to execute the function using an onRequest
event:
await axios.post(CLOUD_FUNC_URL, payload, {
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${TOKEN}`,
},
});
Currently, I am able to obtain the token successfully from the gcloud CLI
(which works), but not from
await auth().currentUser?.getIdToken();
.