Firebase-functions: What incorrect Metadata-Flavor header at GoogleAuth means?

Created on 1 Jun 2019  路  4Comments  路  Source: firebase/firebase-functions

Related issues

[REQUIRED] Version info

Ask Question

I麓m trying to write to firestore from a onCall firebase function.
My purpose is to update the client when something is written in firestore.

  fireApp.firestore().collection('queries').doc(this.getUser.uid).onSnapshot(snap => {
    snap.exists ?
    snap.docChanges().forEach(async change => {
        if (change.type === "modified") {

Would exist any other alternative to update client side from function progress?
node:

node v 12
firebase-functions:
"firebase-functions": "^2.3.0"

firebase-tools:
firebase tools --version
6.10.0

firebase-admin:
"firebase-admin": "~7.0.0",

[REQUIRED] Test case

let getLinks = fireApp.functions().httpsCallable('getLinks')

                getLinks({
                    query: this.query.string,
                    limit: this.query.limit,
                    country: this.query.country,
                    uid: this.getUser.uid
                }).then(result => {

[REQUIRED] Steps to reproduce

So I麓m trying to write to firestore from this onCall function with this code

functions.js

```const functions = require('firebase-functions');
const admin = require('firebase-admin');

admin.initializeApp();

console.log('initialing functions at ' , new Date().toString())

exports.getLinks = functions.runWith({ timeoutSeconds: 540 }).https.onCall( (data,context) => {

console.log('starting to get links ' , new Date().toString())
console.log('data' , data.query, data.limit, data.country, data.uid)
console.log('context auth', context.auth, 'context.auth.uid', context.auth.uid)
// is there anything like admin.setCredentials(context.auth) necessary here?
const queries = admin.firestore().collection('queries');
let uid = data.uid
console.log('uid', uid);
console.log('queries ref', queries)
//probably when trying to write here is not being allowed
queries.doc(uid).set({LinksArrayLength: 'starting'})
    .then( r => console.log('writing to firestore 1 result', r))
    .catch( err => console.error('writing to firestore 2 error', err))

```

[REQUIRED] Expected behavior

Should create the respective document in the queries collection

[REQUIRED] Actual behavior

writing to firestore 2 error Error: Unexpected error determining execution environment: Invalid response from metadata service: incorrect Metadata-Flavor header.
at GoogleAuth. (H:\nprojetos\whats_app_sender\firebase_sender\vue_sender\wa_sender\functions\node_modules\google-auth-library\build\src\auth\googleauth.js:164:23)
at Generator.throw ()
at rejected (H:\nprojetos\whats_app_sender\firebase_sender\vue_sender\wa_sender\functions\node_modules\google-auth-library\build\src\auth\googleauth.js:20:65)
at processTicksAndRejections (internal/process/task_queues.js:89:5)

Were you able to successfully deploy your functions?

didn麓t try to deploy function yet.. I麓m running it locally through the firebase serve --only functions command

needs-triage

Most helpful comment

Solved
It required propper initialization
const credential = require('./xxxxx.json')

admin.initializeApp({credential: admin.credential.cert(credential), databaseURL: "https://xxx.xxx.firebaseio.com"});

this link (https://www.youtube.com/watch?v=Z87OZtIYC_0)
explains how to initialize it properly

my unexperienced with the sdk yet...

All 4 comments

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not have all the information required by the template. Looks like you forgot to fill out some sections. Please update the issue with more information.

Solved
It required propper initialization
const credential = require('./xxxxx.json')

admin.initializeApp({credential: admin.credential.cert(credential), databaseURL: "https://xxx.xxx.firebaseio.com"});

this link (https://www.youtube.com/watch?v=Z87OZtIYC_0)
explains how to initialize it properly

my unexperienced with the sdk yet...

Thanks for the detailed report and sharing your solution @adrielwerlich. For future issues like these, StackOverflow is usually the best resource as you can get faster help there :) glad you figured it out!

adriel's video link worked perfectly to solve my issue

Was this page helpful?
0 / 5 - 0 ratings