npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

typescript-rest-fireauth

v1.1.3

Published

Firebase token authentication for typescript-rest APIs

Readme

:fire: typescript-rest-fireauth :fire:

Need to add Firebase token authentication to your typescript-rest API?

This project provides a FireAuth decorator that you can place on any typescript-rest API endpoint. It will guard the endpoint, verifying the Firebase ID token passed in with the Authorization header.

As an option, you can also obtain the value of the decoded Firebase ID token for use within your controller.

Usage

Step 1: Installation

Make sure you have typescript-rest installed and that you have configured experimental decorators in your tsconfig.json file. Alternatively, you can use the typescript-rest boilerplate project.

{
  "compilerOptions": {
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  }
}

Then install typescript-rest-fireauth: npm install typescript-rest-fireauth

Step 2: Configuration

Back-end

The first step is to install and initialize the Firebase Admin SDK. Usually this is best done in the function that starts the server. If you're using the boilerplate project, this would be in start.ts.

Then, in your controller class, add the typescript-rest ServiceContext with the @Context decorator to your controller, and also instantiate a property of type admin.auth.Auth. These will be used to obtain request authorization headers and verify the token with Firebase. Also instantiate a property of type DecodedToken if you'd like to use the decoded Firebase ID token.

import { GET, Path, PathParam, Context, ServiceContext } from 'typescript-rest';
import * as admin from 'firebase-admin';
import { FireAuth, DecodedToken } from 'typescript-rest-fireauth';

@Path('/user')
export class UserController {

  //required by typescript-rest-fireauth
  @Context
  private context: ServiceContext;
  private admin: admin.auth.Auth = admin.auth();
  
  //optional - use to obtain the decoded firebase id token 
  private decodedToken: DecodedToken = new DecodedToken();
}

Finally, add the FireAuth decorator to an endpoint that requires authentication.

/**
* Retrieve a User.
*/
@FireAuth()
@Path(':id')
@GET
getUser(@PathParam('id') id: string): Promise<User> {
    return new Promise<User>((resolve, reject)=>{
        this.myService.getUser(id)
          .then((user) => {
              resolve(user);
          })
          .catch((err) => reject(err));
    });
}

Optional: If you added the DecodedToken as a property on your controller, it will be loaded with the decoded Firebase ID token for the current request.


/**
* Retrieve a User.
*/
@FireAuth()
@Path(':id')
@GET
getUser(@PathParam('id') id: string): Promise<User> {
    return new Promise<User>((resolve, reject)=>{
        console.log('user firebase uid is ' + this.decodedToken.uid);
        this.myService.getUserByUid(this.decodedToken.uid)
          .then((user) => {
              resolve(user);
          })
          .catch((err) => reject(err));
    });
}

Front-end

In your front-end app, requests to the FireAuth endpoints must include the Firebase ID token as a Bearer token in the Authorization header.

Check out the Google documentation on obtaining Firebase ID tokens on the client side.

Here is a sample request:

GET /user/12345 HTTP/1.1
Host: localhost:3000
Content-Type: application/json
Authorization: Bearer [firebase id token]

Gotchas

If the properties required by typescript-rest-fireauth remain unread in your controller, you may receive an error upon build. You can resolve this by changing noUnusedLocals to false in your tsconfig.json.

Release Notes

1.0.0 - Initial release.

1.1.0 - Switched from Decode parameter decorator to DecodedToken controller property in order to fulfill decoded Firebase ID token, because typescript-rest does not allow additional parameters in POST/PUT methods.

1.1.3 - Bumped firebase-admin to v9.6. This may introduce breaking changes. Please open an issue if you see any.