Skip to content
Docs
Usage guide
Usage in getServerSideProps

Usage in getServerSideProps

Example usage of getApiRequestTokens function in getServerSideProps (opens in a new tab)

import { GetServerSidePropsContext } from "next";
import { getApiRequestTokens } from "next-firebase-auth-edge";
 
export async function getServerSideProps(context: GetServerSidePropsContext) {
  const tokens = await getApiRequestTokens(context.req, {
    apiKey: 'XXxxXxXXXxXxxxxx_XxxxXxxxxxXxxxXXXxxXxX',
    cookieName: 'AuthToken',
    cookieSignatureKeys: ['Key-Should-Be-at-least-32-bytes-in-length'],
    serviceAccount: {
      projectId: 'your-firebase-project-id',
      clientEmail: 'firebase-adminsdk-nnw48@your-firebase-project-id.iam.gserviceaccount.com',
      privateKey: '-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n'
    },
    // Optional
    tenantId: 'your-tenant-id',
  });
 
  return { props: { tokens } };
}