/nestjs-firebase-auth-middleware

Middleware to validate JWT tokens from Firebase

Primary LanguageTypeScript

NestJS Firebase Auth middleware

NestJS middleware to verify tokens from Firebase.

Usage

import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
import { FirebaseAuthMiddleware } from 'nestjs-firebase-auth-middleware';
import { AppController } from './app.controller';

@Module({
  imports: [],
  controllers: [AppController],
  providers: [],
})
export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer.apply(FirebaseAuthMiddleware)
      .forRoutes(AppController);
  }
}

Access the user

Once the token is validated, the user data will be added to the request. You can access it like so:

import { Controller, Get, Req } from '@nestjs/common';
import { Request } from 'express';

@Controller()
export class AppController {
  constructor() {}
  @Get()
  index(@Req() request: Request) {
    console.log(request.user);
  }
}