App Check support
Library provides Firebase App Check (opens in a new tab) support. Follow starter example README (opens in a new tab) for more information on integrating your app with App Check.
In order to make next-firebase-auth-edge
work with App Check, you need to send X-Firebase-AppCheck
header with App Check token when making a call to /api/login
endpoint, as 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
You can use getAppCheck
from next-firebase-auth-edge/lib/app-check
if you need to create or verify App Check token explicitly, as in provided example:
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);