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

@navarrotech/use-firebase-auth

v0.0.2

Published

Express middleware for Firebase Authentication

Readme

Express Firebase Auth

This package provides a simple and minimalistic Firebase authentication middleware designed for Express.js applications. It validates Firebase JWTs issued on the frontend, ensuring that backend services are secure and requests are authenticated. This is great for developers looking to implement Firebase authentication outside of Google Cloud environments. The goal is to be able to write custom Node.js logic without compromising on security. Whether you're developing a small project or a large-scale application, use-firebase-auth simplifies the integration of Firebase Auth with your server-side logic.

Installation

npm install use-firebase-auth
// or
yarn add use-firebase-auth

Once npm installed the module, you need to set up a bit on the frontend and backend.

Backend implementation:

Short example:

import useFirebaseAuth, {
    type SessionedRequest,
    type UserSession
} from "use-firebase-auth"

// Middleware that uses the auth:
app.use(
    useFirebaseAuth({
        firebaseApp
    })
)

Full example:

// Firebase Admin:
import * as firebase from 'firebase-admin'
import credentials from "./firebase.json"

// Express and middleware:
import express from "express"
import useFirebaseAuth, {
    type SessionedRequest,
    type UserSession
} from "use-firebase-auth"

const app = express()

const firebaseApp = firebase.initializeApp({
    credential: firebase.credential.cert(credentials),
    databaseURL: "/* Your database url */"
})

// Middleware that uses the auth:
app.use(
    useFirebaseAuth({
        firebaseApp
    })
)

// Sample route
app.all('/hello', (request, response) => {
    const sessionedRequest = request as SessionedRequest

    // You can get the typed results like so:
    const authorized: boolean = sessionedRequest.authorized
    const user: UserSession = sessionedRequest.user

    console.log({ authorized, user })
    response.send('Hello World')
})

// Start the server
app.listen(3001, () => {
    console.log('Server is running on port 3001')
})

Frontend implementation

It's important that you use the authorization header when sending requests your backend node server from your frontend like so:

// Initialize your app like normal:
const app = initializeApp({ /* Credentials */ })
const auth = getAuth(app)

// Each request, just include a Bearer token with the currentUser's token:
const token = await auth.currentUser?.getIdToken()
const request = fetch('http://localhost:3001/hello', {
    headers: {
        'Authorization': 'Bearer ' + token
    },
})

Security Best Practices

When using use-firebase-auth, it's important to follow security best practices to protect your applications:

  • Secure Your Firebase Credentials: Keep your Firebase credentials file secure and never expose it in your version control or to the frontend.
  • Use HTTPS: Ensure that your backend and frontend communicate over HTTPS to protect the integrity and privacy of the authentication tokens being transmitted.

Contribution

Contributions are welcome! If you would like to contribute to this project, please follow these steps:

  1. Fork the repository.
  2. Create a new branch: git checkout -b feature/your-feature-name
  3. Use yarn run install to download dependencies
  4. You'll need a test firebase project. Visit the firebase console and create a test project. Ensure auth is enabled on the project, and use signing in with username/password.
  5. Create some firebase credentials for web, and add the credentials to test/index.html on line 33
  6. Create some firebase admin SDK credentials and add the credentials to test/firebase.ts
  7. Use yarn run dev to start a test express.js server for developing in, and yarn run serve-test to start a sample frontend for testing a auth connection to.
  8. Build the new changes, with yarn run build
  9. Before committing, ensure you remove your own credentials that you added for development.
  10. Make your changes and commit them: git commit -m 'Add your feature'
  11. Push to the branch: git push origin feature/your-feature-name
  12. Open a pull request.

License

This project is licensed under the MIT License.