Skip to content
Docs
App Check

App Check Support

This library provides support for Firebase App Check (opens in a new tab). To learn how to integrate App Check into your app, follow the instructions in the starter example README (opens in a new tab).

To use next-firebase-auth-edge with App Check, you need to include the X-Firebase-AppCheck header with the App Check token when making a call to the /api/login endpoint. You can see how this works in this example (opens in a new tab).

import { getToken } from "@firebase/app-check";
import { getAppCheck } from "../app-check";
 
const appCheckTokenResponse = await getToken(getAppCheck(), false);
 
await fetch("/api/login", {
  method: "GET",
  headers: {
    Authorization: `Bearer ${token}`,
    "X-Firebase-AppCheck": appCheckTokenResponse.token,
  },
});

Advanced Usage

If you need to explicitly create or verify an App Check token, you can use the getAppCheck function from next-firebase-auth-edge/lib/app-check. You can see an example of how to do this below:

import { getAppCheck } from "next-firebase-auth-edge/lib/app-check";
 
// Optional in authenticated Google Cloud Run environment. Otherwise required.
const serviceAccount = {
  projectId: "firebase-project-id",
  privateKey: "firebase service account private key",
  clientEmail: "firebase service account client email",
};
 
// Optional. Specify if your project supports multi-tenancy
// https://cloud.google.com/identity-platform/docs/multi-tenancy-authentication
const tenantId = "You tenant id";
 
const { createToken, verifyToken } = getAppCheck({ serviceAccount, tenantId });
const appId = "your-app-id";
 
// Optional
const createTokenOptions = {
  ttlMillis: 3600 * 1000,
};
 
const token = await createToken(appId, createTokenOptions);
 
// Optional
const verifyTokenOptions = {
  currentDate: new Date(),
};
 
const response = await verifyToken(token, verifyTokenOptions);