mirror of
https://github.com/hanzoai/ui.git
synced 2026-11-21 00:18:41 +00:00
- 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)
72 lines
1.7 KiB
TypeScript
72 lines
1.7 KiB
TypeScript
/**
|
|
* Auth Provider Registry
|
|
*
|
|
* Allows registration of pluggable auth providers.
|
|
* Firebase support is available via @hanzo/auth-firebase (optional).
|
|
*/
|
|
|
|
import type AuthService from './auth-service'
|
|
import type { AuthServiceConf, HanzoUserInfoValue } from '../types'
|
|
|
|
export type AuthServiceFactory = new (
|
|
conf: AuthServiceConf,
|
|
user: HanzoUserInfoValue | null
|
|
) => AuthService
|
|
|
|
// Registry of available auth providers
|
|
const providers = new Map<string, AuthServiceFactory>()
|
|
|
|
// Current active provider
|
|
let activeProvider: string | null = null
|
|
|
|
/**
|
|
* Register an auth provider
|
|
*
|
|
* @example
|
|
* ```ts
|
|
* import { FirebaseAuthService } from '@hanzo/auth-firebase'
|
|
* import { registerAuthProvider } from '@hanzo/auth'
|
|
*
|
|
* registerAuthProvider('firebase', FirebaseAuthService)
|
|
* ```
|
|
*/
|
|
export function registerAuthProvider(name: string, factory: AuthServiceFactory): void {
|
|
providers.set(name, factory)
|
|
// Auto-activate if this is the first provider
|
|
if (!activeProvider) {
|
|
activeProvider = name
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Set the active auth provider by name
|
|
*/
|
|
export function setActiveProvider(name: string): void {
|
|
if (!providers.has(name)) {
|
|
throw new Error(`Auth provider '${name}' is not registered`)
|
|
}
|
|
activeProvider = name
|
|
}
|
|
|
|
/**
|
|
* Get the active auth provider factory
|
|
*/
|
|
export function getActiveProvider(): AuthServiceFactory | null {
|
|
if (!activeProvider) return null
|
|
return providers.get(activeProvider) ?? null
|
|
}
|
|
|
|
/**
|
|
* Check if any auth provider is registered
|
|
*/
|
|
export function hasAuthProvider(): boolean {
|
|
return providers.size > 0
|
|
}
|
|
|
|
/**
|
|
* Get list of registered provider names
|
|
*/
|
|
export function getRegisteredProviders(): string[] {
|
|
return Array.from(providers.keys())
|
|
}
|