DEV Community

Cover image for Nest JS for Beginners #5: Integrating Firebase authentication into NestJS application
Mithun 👨‍💻
Mithun 👨‍💻

Posted on

Nest JS for Beginners #5: Integrating Firebase authentication into NestJS application

Step 1: Set up Firebase Project

1) Create a Firebase Project:

Go to the Firebase Console.
Click on "Add Project" and follow the setup instructions.

Image description

2) Enable Authentication:

In the Firebase Console, navigate to "Authentication" on the left sidebar.
Enable the authentication method you want to use (e.g., Email/Password, Google, etc.).

Image description

3) Get Firebase Configuration:

In the Firebase Console, click on the gear icon (Settings) and go to "Project Settings."
Scroll down to the "Your apps" section and click on the Firebase SDK snippet.
Choose "Config" and copy the configuration object. You'll need this in your NestJS application.

Image description

Step 2: Install Firebase in NestJS

1 Install Firebase in Your NestJS Project:

npm install firebase

2 Create a Firebase Service:

Create a new file firebase.service.ts in a services folder (you can create this folder in your project).

Image description

Step 3: Implement Firebase Authentication in a Controller

1 Create an Authentication Controller:

Create a new controller (e.g., auth.controller.ts) where you'll handle authentication.

Image description

2 Update AppModule to Include AuthController:

Open your app.module.ts file and add the AuthController to the controllers array.

Image description

Step 4: Test Authentication Endpoint

Run Your NestJS Application:
npm run start:dev

Test the Authentication Endpoint:

Open your browser or use a tool like Postman.
Send a GET request to http://localhost:3000/auth/login.
Check the response to see if the authentication works.

Image description

Final Project Link:
https://github.com/Mithun1508/Nest-Postgres-Sequelize

Top comments (0)