My code:
import admin from "firebase-admin";
const path = `./service-account-key.json`;
admin.initializeApp({
credential: path,
});
// Get uid from user email
var uid = "";
const email = "bearcodes@outlook.com";
admin.auth().getUserByEmail(email)
.then(function (userRecord) {
uid = userRecord.uid;
console.log(userRecord.uid)
})
.catch(function (error) {
console.log("Error fetching user data:", error);
});
This is the error I keep getting:
C:\Users\bearc\Downloads\flaskTesting\node_modules\firebase-admin\lib\utils\error.js:44
var _this = _super.call(this, errorInfo.message) || this;
^
FirebaseAppError: Invalid Firebase app options passed as the first argument to initializeApp() for the app named "[DEFAULT]". The "credential" property must be an object which implements the Credential interface.
at FirebaseAppError.FirebaseError [as constructor] (C:\Users\bearc\Downloads\flaskTesting\node_modules\firebase-admin\lib\utils\error.js:44:28)
at FirebaseAppError.PrefixedFirebaseError [as constructor] (C:\Users\bearc\Downloads\flaskTesting\node_modules\firebase-admin\lib\utils\error.js:90:28)
at new FirebaseAppError (C:\Users\bearc\Downloads\flaskTesting\node_modules\firebase-admin\lib\utils\error.js:125:28)
at new FirebaseApp (C:\Users\bearc\Downloads\flaskTesting\node_modules\firebase-admin\lib\firebase-app.js:134:19)
at FirebaseNamespaceInternals.initializeApp (C:\Users\bearc\Downloads\flaskTesting\node_modules\firebase-admin\lib\firebase-namespace.js:77:19)
at FirebaseNamespace.initializeApp (C:\Users\bearc\Downloads\flaskTesting\node_modules\firebase-admin\lib\firebase-namespace.js:387:30)
at file:///C:/Users/bearc/Downloads/flaskTesting/applycustomclaims.js:5:7
at ModuleJob.run (node:internal/modules/esm/module_job:183:25)
at async Loader.import (node:internal/modules/esm/loader:178:24)
at async Object.loadESM (node:internal/process/esm_loader:68:5) {
errorInfo: {
code: 'app/invalid-app-options',
message: 'Invalid Firebase app options passed as the first argument to initializeApp() for the app named "[DEFAULT]". The "credential" property must be an object which implements the Credential interface.'
},
codePrefix: 'app'
}
Can anyone help me with what the hell is going on?
I have set my package.json
file with this parameter: "type": "module"
so I can use the "import" statement.