david takidzew
david takidzew

Reputation: 1

Invalid parent project. Either parent project doesn't exist or didn't enable multi-tenancy

I have node.js as back-end, there I use firebase and firebase-admin. when I use firebase-admin configuration like that:

import admin from "firebase-admin";
import { cert } from "firebase-admin/app";

const Service = require("../adminSDK_service.json");

const { PRIVATE_KEY, PROJECT_ID, CLIENT_EMAIL } = process.env;

const fireBase_Admin = admin.initializeApp({
  credential: cert(Service),
  databaseURL: process.env.DATA_BASE_URL,
});

export default fireBase_Admin;

here everything is fine but problem is that I don't know where I can save json file to be secured.

I know way to resolve this problem, I mean make github repository private, but I build this project for my portfolio so I want to be visible for everyone. then I read documentation of "cert" function and as I got there we need only three arguments:

  1. projectId 2) clientEmail 3) privateKey

import admin from "firebase-admin";
import { cert } from 'firebase-admin/app'

const Service = require("../adminSDK_service.json");

const { PRIVATE_KEY, PROJECT_ID, CLIENT_EMAIL } = process.env;

const fireBase_Admin = admin.initializeApp({
  credential: cert({
    privateKey: PRIVATE_KEY?.replace(/\\n/g, "\n"),
    projectId: PROJECT_ID,
    clientEmail: CLIENT_EMAIL,
  }),
  databaseURL: process.env.DATA_BASE_URL,
});

export default fireBase_Admin;

And I set the values there from env, but when I try to sign In. I get the error:

Invalid parent project. Either the parent project doesn't exist or didn't enable multi-tenancy.

in the sign-in function, I try to get the user to check if such a user exists like that:

// find user
const user = await Admin.auth().getUserByEmail(email);

console.log(user);

if (!user) {
  return {
    status: false,
    message: "error!",
  };
}

and when I remove it, works everything fine... so..

so I am confused if "cert" requires only three arguments this means it uses three values from the JSON file yes?

I also heard about Google Secret Manager but I don't understand how I can use it, if you have any source or video tutorial please write in the comment

I have hope you will help me.

Upvotes: 0

Views: 161

Answers (1)

nerex_rs
nerex_rs

Reputation: 19

I am working in Nest.js (a framework for Node.js). I am not using cert, I am calling applicationDefault() that runs the environment variable Google application credentials in the archive .env. The value of that variable is your serviceAccounKey.json of your Firebase project and thanks to the initialization of the dotenv in the main.ts, everything can work.

I had the same error for the project_id that must be a string, it seems that .env doesn't know if a value is a string or not so I had to call in my .env my serviceAccountKey.json that has the normal configuration of Firebase SDK:

auth.service.ts



import { Injectable } from '@nestjs/common';
import * as admin from 'firebase-admin';
import { applicationDefault } from 'firebase-admin/app';

@Injectable()
export class AuthService {
  private readonly firebaseAdmin: admin.app.App;
  constructor() {
    this.firebaseAdmin = admin.initializeApp({
      credential: applicationDefault(),
    });
  }



main.ts

    import * as dotenv from 'dotenv';
    dotenv.config();

.env

    GOOGLE_APPLICATION_CREDENTIALS=./serviceAccountKey.json

And that worked for me

Upvotes: 0

Related Questions