Skip to Content
gentlemans-stack
ReferencePlatforms

@gentlemans-stack/auth-firebase

Firebase Auth ID-token providers for @gentlemans-stack/auth's AuthProvider contract. A GCP platform package: only services and apps import it, never the core (see the platforms zone in .fallowrc.json).

Two providers, each behind its own subpath so a service loads only the SDK it uses. There is no root export.

ImportExportUse it when
@gentlemans-stack/auth-firebase/admincreateFirebaseAdminAuthProvider<TLogger, TOwner>({ resolveOwner })The service already runs firebase-admin and must cut off disabled or revoked accounts at once.
@gentlemans-stack/auth-firebase/jwkscreateFirebaseJwksAuthProvider({ projectId, jwksUrl? }), FIREBASE_JWKS_URLVerifying the token is enough and the service should not pull in firebase-admin.

API

  • ./admin: createFirebaseAdminAuthProvider (config: FirebaseAdminAuthProviderConfig), using firebase-admin.
  • ./jwks: createFirebaseJwksAuthProvider (config: FirebaseJwksAuthProviderConfig), without firebase-admin; FIREBASE_JWKS_URL.

admin: firebase-admin, with revocation

createFirebaseAdminAuthProvider<TLogger, TOwner extends Record<string, unknown>>({
	resolveOwner: (token: DecodedIdToken, logger: TLogger) => Promise<TOwner | null>,
}): AuthProvider<{ logger: TLogger }, TOwner & { firebaseAuthID: string }>
  • Calls getAuth().verifyIdToken(token, true). checkRevoked also rejects disabled accounts, at the cost of one Firebase Auth API call per request.
  • Then resolveOwner(decodedToken, context.logger) on every request, so role and plan changes apply without a new sign-in. The service owns this (lookup, first-request upsert from the token's profile). null → USER_UNAUTHENTICATED (invalid_token).
  • Principal: { claims: { ...owner, firebaseAuthID: uid }, id: uid, roles: [] }.
  • Needs a default Firebase app: call initializeApp(...) from firebase-admin/app at service startup.

jwks: no firebase-admin

createFirebaseJwksAuthProvider({ projectId, jwksUrl = FIREBASE_JWKS_URL }): {
	verifyToken: (token: string) => Promise<Principal<JwtProfileClaims>>;
}
  • Wraps createJwtAuthProvider with Google's securetoken JWKS: RS256 signature, iss = https://securetoken.google.com/<projectId>, aud = projectId, exp, and a non-empty sub (the uid).
  • Principal: { claims: { email?, name?, picture? }, id: uid, roles: [] }. No owner lookup; wrap it or chain it if the service needs one.
  • No revocation check: a disabled account keeps working until its ID token expires (up to an hour).
  • jwksUrl is overridable for tests only.

Testing

pnpm nx test auth-firebase. The admin specs mock firebase-admin/auth with vi.hoisted + vi.mock; the jwks specs sign real RS256 tokens against a local JWKS server. No real credentials. Guidance: the nested platforms/gcp/.claude/skills/firebase-auth-tests skill.

On this page