
Let's Implement LINE Login + Firebase Custom Claims Token with NestJS
Hello friends, it's me Arm again. Today, we’ll dive into LINE Login using Firebase Custom Claims Token.
This article builds on one written by Tee about LINE Login. If you're not yet familiar with what LINE Login is or why we need to integrate it with Firebase, check out the article below:
Create a Firebase Custom Authentication System with LINE Login v2.1
Over the past year, I’ve received quite a few questions from members of the Firebase Thailand page about implementing Custom Authentication…
[medium.com]
Let’s get started! Today we’ll use NestJS, which is quite a modern framework compared to Express, and it’s gaining a lot of popularity. It’s built entirely using TypeScript and follows 100% OOP principles, highlighting its strengths in scalability and maintainability—something every OOP enthusiast loves.
If you already have a solid OOP background, you’ll probably enjoy using it!
But hey, we’re not here to promote NestJS—there are already tons of people doing that. 😂
I'll assume everyone reading this has at least tried NestJS, so let’s not waste time. Let's go!
Step 1: Create a NestJS Project
You’ll get a project scaffold like this.
Then run:
Now you’ll have a ready-to-develop folder structure.
-
auth.service.ts
-
auth.module.ts
-
auth.controller.ts
Next, we’ll create a library for dependency injection, specifically to inject Firebase:
Delete the default contents under src/common
, and create firebase.module.ts
and firebase.service.ts
instead.
Intermission: Set Up Firebase
Go to Firebase Console, navigate to your Project settings, and then to the Service accounts tab.
Click Generate new private key — this gives you a .json
file.
For security, it’s recommended to create a .env
file and store the values from the .json
there.
Don't forget to add
.env
to your.gitignore
!
Install Firebase Admin SDK:
In firebase.service.ts
, you'll create a JSON object based on the service account file, but read the values from env
variables instead. Then, call the initializeApp
method.
In firebase.module.ts
, configure it accordingly.
Creating the Frontend Login (LINE Login)
Since our system needs a frontend for login, let’s create a basic frontend login flow first.
In utils/firebase.ts
, create a Firebase utility file.
For LINE Login, use the token endpoint:
https://api.line.me/oauth2/v2.1/token
To implement LINE Login, you’ll need to create a login link via the frontend.