3
votes

My end goal is to get user email, using user's id. So far I figured out I need to use the firebase admin SDK. Right now I have this code:

var admin = require("firebase-admin");

var serviceAccount = require("./serviceAccountKey");

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

export default admin;

The serviceAccountKey is the file I downloaded from my firebase project here (Sorry it's in Polish)

enter image description here

I tried using this video as a tutorial/reference

https://youtu.be/WtYzHTXHBp0

And right now, when I try to do anything I get this in the npm start console:

20:22-48 Critical dependency: the request of a dependency is an expression

   ./node_modules/google-gax/node_modules/grpc/src/grpc_extension.js
32:12-33 Critical dependency: the request of a dependency is an expression

   ./node_modules/hash-stream-validation/index.js
Module not found: Can't resolve 'fast-crc32c' in '/home/iron/Documents?>/Projects/zdajto-admin-panel/node_modules/hash-stream-validation'

Search for the keywords to learn more about each warning. To ignore, add // eslint-disable-next-line to the line before.

And this in the browser console:

Error fetching user data: Error: "Credential implementation provided to initializeApp() via the "credential" property failed to fetch a valid Google OAuth2 access token with the following error: "Failed to parse access token response: Error: Error while making request: XHR error. Error code: undefined"."

What am I missing?

1
You might find it a lot easier to set this up using Firebase Tools - firebase.google.com/docs/functions/get-startedPhilip

1 Answers

2
votes

Firebase Admin SDK is not available for Javascript, here the prerequisites: https://firebase.google.com/docs/admin/setup#prerequisites

So, for example, you cannot operate as admin in a web page for security reason, but only in a privileged environment (like a server).

I'm creating a web administration interface for my project, where admin operations are performed in Cloud Functions.