Nestjs Firebase Admin Module
Description
Firebase Admin module for Nest.
Installation
$ npm i --save firebase-admin @cuaklabs/nestjs-firebase-admin
Quick Start
Initialization
import { FirebaseAdminModule } from '@cuaklabs/nestjs-firebase-admin';
@Module({
imports: [FirebaseAdminModule.forRoot()],
})
export class AppModule {}
import { FirebaseAdminModule } from '@cuaklabs/nestjs-firebase-admin';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { AppOptions } from 'firebase-admin';
@Module({
imports: [
FirebaseAdminModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (configService: ConfigService): AppOptions => {
return {
databaseURL: configService.get('DATABASE_URL'),
};
},
}),
],
})
export class AppModule {}
Inject Providers
import { Auth } from 'firebase-admin/auth';
import { CatService } from './CatService';
import { FirebaseAdminModule } from '@cuaklabs/nestjs-firebase-admin';
@Module({
imports: [FirebaseAdminModule.injectProviders([Auth])],
providers: [CatService],
})
export class CatModule {}
import { Auth } from 'firebase-admin/auth';
import { InjectFirebaseProvider } from '@cuaklabs/nestjs-firebase-admin';
export class CatService {
constructor(@InjectFirebaseProvider(Auth) private readonly auth: Auth) {}
public doSomething(): void {
}
}
Multiple apps/connections
Initialization
import { FirebaseAdminModule } from '@cuaklabs/nestjs-firebase-admin';
@Module({
imports: [FirebaseAdminModule.forRoot([{ name: 'app-name' }])],
})
export class AppModule {}
import { FirebaseAdminModule } from '@cuaklabs/nestjs-firebase-admin';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { AppOptions } from 'firebase-admin';
@Module({
imports: [
FirebaseAdminModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (configService: ConfigService): AppOptions => {
return [
{
name: 'app-name',
appOptions: {
databaseURL: configService.get('DATABASE_URL'),
},
},
];
},
}),
],
})
export class AppModule {}
Inject Providers
import { Auth } from 'firebase-admin/auth';
import { CatService } from './CatService';
import { FirebaseAdminModule } from '@cuaklabs/nestjs-firebase-admin';
@Module({
imports: [FirebaseAdminModule.injectProviders([Auth], 'app-name')],
providers: [CatService],
})
export class CatModule {}
import { Auth } from 'firebase-admin/auth';
import { InjectFirebaseProvider } from '@cuaklabs/nestjs-firebase-admin';
export class CatService {
constructor(@InjectFirebaseProvider(Auth, 'app-name') private readonly auth: Auth) {}
public doSomething(): void {
}
}