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
Most notable features are:
handleValidToken
andgetToken
functions now exposecustomToken
which can be used together with Firebase'ssignInWithCustomToken
method to authenticate with Firebase Client SDKs- Introduced
enableMultipleCookies
option in Authentication Middleware. It is recommended to set this option totrue
to avoid cookie size issues. See middleware docs for more information - Introduced
getValidIdToken
andgetValidCustomToken
helper functions to ensure token stays valid in long-running client-side sessions. See client-side APIs docs for more information - Updates several advanced methods
See 1.6.x canary release for detailed API changes description
With npm
npm install next-firebase-auth-edge
With yarn
yarn add next-firebase-auth-edge
With pnpm
pnpm add next-firebase-auth-edge