Next.js Firebase Authentication for Edge and Node.js runtimes. Use Firebase Authentication with latest Next.js features.
The starter demo is available at next-firebase-auth-edge-starter.vercel.app
You can find source code for the demo in examples/next-typescript-starter
If you're new to Firebase or Next.js, you can follow this comprehensive, step-by-step guide on integrating Firebase Authentication with Next.js using next-firebase-auth-edge library:
https://hackernoon.com/using-firebase-authentication-with-the-latest-nextjs-features
Official library documentation can be found at https://next-firebase-auth-edge-docs.vercel.app
Official firebase-admin
library relies heavily on Node.js internal crypto
library and primitives that are unavailable inside Next.js Edge Runtime.
This library aims to solve the problem of creating and verifying Custom ID Tokens using Web Crypto API available inside Edge runtimes.
next-firebase-auth-edge
is compatible with latest Next.js features, such as App Router or Server Components
To allow gradual adoption of latest Next.js features, next-firebase-auth-edge
works interchangeably with getServerSideProps and legacy Api Routes
- Supports latest Next.js features
- Zero-bundle size
- Minimal configuration: In contrary to other libraries, you don't have to define your own API routes or update your
next.config.js
file. All heavy lifting is done by the middleware. - Secure: Uses jose for JWT validation. Signs user cookies with rotating keys to mitigate the risk of cryptanalysis attacks
handleInvalidToken
is now being called withInvalidTokenReason
to give developer more control over authentication flow- You can now use the library without providing service account credentials in authenticated Google Cloud Run environment
- You can now use the library in Firebase Hosting environment by changing
cookieName
to__session
- You can enable debug mode in authentication middleware
With npm
npm install next-firebase-auth-edge
With yarn
yarn add next-firebase-auth-edge
With pnpm
pnpm add next-firebase-auth-edge