Files
ui/pkg/auth-firebase/README.md
zeekay ce8cf94ef8 feat(auth): make Firebase optional, add @hanzo/auth-firebase package
- Create @hanzo/auth-firebase v1.0.0 as optional Firebase provider
- Update @hanzo/auth v2.6.0 with pluggable auth provider system
- Update @hanzo/commerce v7.4.0 with optional Firebase peer dependency
- Add StubAuthService for graceful failures when no provider configured
- Add registerAuthProvider() for runtime provider registration

BREAKING CHANGE: Firebase is no longer bundled with @hanzo/auth.
Install @hanzo/auth-firebase and register it if you need Firebase auth:

  import { FirebaseAuthService } from '@hanzo/auth-firebase'
  import { registerAuthProvider } from '@hanzo/auth'
  registerAuthProvider('firebase', FirebaseAuthService)
2026-01-24 13:14:08 -08:00

2.6 KiB

@hanzo/auth-firebase

Firebase authentication provider for @hanzo/auth.

Installation

This package is OPTIONAL. Only install if you need Firebase authentication.

pnpm add @hanzo/auth-firebase firebase firebase-admin

Usage

Client-side Setup

Register the Firebase auth provider in your app's entry point:

// app/providers.tsx or similar
import { FirebaseAuthService, isFirebaseConfigured } from '@hanzo/auth-firebase'
import { registerAuthProvider } from '@hanzo/auth'

// Register Firebase as the auth provider (only if configured)
if (isFirebaseConfigured()) {
  registerAuthProvider('firebase', FirebaseAuthService)
}

Server-side Setup

For server-side authentication (Next.js Server Components, API routes):

// In Server Components or API routes
import { getUserServerSide, createSessionCookie } from '@hanzo/auth-firebase/server'

// Get current user from session cookie
const user = await getUserServerSide()

// Create session cookie after login
const sessionCookie = await createSessionCookie(idToken, { expiresIn: 60 * 60 * 24 * 5 * 1000 })

Environment Variables

Client-side (NEXT_PUBLIC_*)

NEXT_PUBLIC_FIREBASE_API_KEY=your-api-key
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=your-project.firebaseapp.com
NEXT_PUBLIC_FIREBASE_PROJECT_ID=your-project
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=your-project.appspot.com
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=123456789
NEXT_PUBLIC_FIREBASE_APP_ID=1:123456789:web:abcdef

Server-side (Firebase Admin)

FIREBASE_PROJECT_ID=your-project
FIREBASE_CLIENT_EMAIL=[email protected]
FIREBASE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n"

Without Firebase

If you don't need Firebase, simply don't install this package. The @hanzo/auth package works without Firebase - it will use a stub implementation that returns graceful failures for all auth operations.

Exports

Main (@hanzo/auth-firebase)

  • FirebaseAuthService - The Firebase auth service implementation
  • isFirebaseConfigured() - Check if Firebase client config is present

Server (@hanzo/auth-firebase/server)

  • getUserServerSide() - Get current user from session cookie
  • generateCustomToken() - Generate a custom token
  • createSessionCookie() - Create a session cookie from ID token
  • revokeAllSessions() - Revoke all sessions for current user
  • isFirebaseAdminConfigured() - Check if Firebase Admin is configured

Service (@hanzo/auth-firebase/service)

  • Low-level Firebase auth functions (for advanced use)