nestjs-firebase-admin icon indicating copy to clipboard operation
nestjs-firebase-admin copied to clipboard

Not working with firebase 10

Open RoyBkker opened this issue 3 years ago • 7 comments

When updating to firebase 10, I receive errors that initializing is not working anymore.

import { FirebaseAdminModule } from '@aginix/nestjs-firebase-admin';
import { Module } from '@nestjs/common';
import { join } from 'path';
import { cert } from 'firebase-admin/app';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const serviceAccount = require(join(
  __dirname,
  `config/firebase-admin-${process.env.FIREBASE_ENV}.json`,
));

console.log(serviceAccount);

@Module({
  imports: [
    FirebaseAdminModule.forRootAsync({
      useFactory: () => ({
        credential: cert(serviceAccount),
      }),
    }),
  ],
})
export class FirebaseModule {}

ERROR Failed to determine project ID for Auth. Initialize the SDK with service account credentials or set project ID as an app option.

RoyBkker avatar Dec 15 '21 09:12 RoyBkker

Also experiencing the same issue.

DavidAmunga avatar Jan 21 '22 13:01 DavidAmunga

Also experiencing the same issue.

Same thing here, did you fix it?

Bahad001 avatar Feb 06 '22 16:02 Bahad001

Same for me. @n3n Would you have to time to fix this issue?

shahkeyur avatar Mar 07 '22 18:03 shahkeyur

Look's like it's not maintained anymore

gaetansenn avatar Mar 28 '22 16:03 gaetansenn

You need to include projectId in useFactory

FirebaseAdminModule.forRootAsync({
      useFactory: () => ({
        credential: admin.credential.cert({
          private_key: process.env.FIREBASE_PRIVATE_KEY,
          client_email: process.env.FIREBASE_CLIENT_EMAIL,
          project_id: process.env.FIREBASE_PROJECT_ID,
          google_cloud_project: process.env.FIREBASE_PROJECT_ID,
        } as Partial<admin.ServiceAccount>),
        projectId: process.env.FIREBASE_PROJECT_ID,
        databaseURL: process.env.FIREBASE_DATABASE_URL,
      }),
    }),

jeremytsngtsng avatar Oct 24 '22 06:10 jeremytsngtsng

@jeremytsngtsng your solution doesn't work

Problem is that this lib will install its own firebase-admin package (v9). To avoid it, add to your package.json

  "resolutions": {
    "firebase-admin": "^11.3.0"
  },

younes0 avatar Nov 26 '22 15:11 younes0

  "resolutions": {
    "firebase-admin": "^11.3.0"
  },

@younes0 this is works so perfectly! You saved me, Thank you 👍

kyle-seongwoo-jun avatar Mar 10 '23 08:03 kyle-seongwoo-jun