firebase/quickstart-nodejs

TypeError: Cannot read property 'JWT' of undefined

SirLancelot-OG opened this issue ยท 6 comments

Line 25: TypeError: Cannot read property 'JWT' of undefined

Looking at the google object, this path to JWT does not exist. Instead it requires:

jwtClient = new google.google.auth.JWT

@Ether0x nice catch! I noticed that the pattern shown by the googleapis docs is:

var {google} = require('googleapis');

// ...

google.auth.JWT

So I went with that.

rbar2 commented

I am getting this same error but have tried both ways above and the one outlined here: .

I had been doing it this way with no trouble but redeployed (without changing anything) this function for the first time in a bit later and now this is crashing with the error above:

var google = require("googleapis");

// Load the service account key JSON file.
var serviceAccount = require("path/to/serviceAccountKey.json");

// Define the required scopes.
var scopes = [
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/firebase.database"
];

// Authenticate a JWT client with the service account.
var jwtClient = new google.auth.JWT(
serviceAccount.client_email,
null,
serviceAccount.private_key,
scopes
);

Any ideas what could be causing this issue? ๐Ÿ™

@samtstern I think you are actually right. There is a good thread here.

From Justin's comment:

  1. Make sure you didn't npm install google-auth-library. If you did, delete it from your package.json, and run npm install again.

  2. Import the library using const {google} = require('googleapis');, notice the {} around google.

  3. In your callback, instead of looking for response.items, use response.data.items. This will be required in any of the callbacks coming from the API.

@rbar2 you needs to be add var {google} = require("googleapis"); instead of var google = require("googleapis");

@ThomasGHenry thanks for catching that, I will get it updated.