@proveanything/smartlinks-auth-ui
Version:
Lightweight React authentication UI components with bearer token support and Smartlinks SDK integration
253 lines • 8.66 kB
TypeScript
export type AuthProvider = 'email' | 'google' | 'phone' | 'magic-link';
export type AuthLogger = {
log?: (...args: any[]) => void;
warn?: (...args: any[]) => void;
error?: (...args: any[]) => void;
debug?: (...args: any[]) => void;
} | ((...args: any[]) => void);
export type EmailVerificationMode = 'immediate' | 'verify-then-auto-login' | 'verify-then-manual-login';
export interface EmailTemplate {
subject?: string;
header?: string;
introText?: string;
buttonText?: string;
footerText?: string;
}
export interface EmailTemplates {
passwordReset?: EmailTemplate;
emailVerification?: EmailTemplate;
magicLink?: EmailTemplate;
accountActivation?: EmailTemplate;
}
export interface EmailBrandingConfig {
logoUrl?: string;
footerHtml?: string;
}
export interface AuthUIConfig {
branding?: {
logoUrl?: string;
title?: string;
subtitle?: string;
primaryColor?: string;
secondaryColor?: string;
backgroundColor?: string;
buttonStyle?: 'rounded' | 'square';
fontFamily?: string;
customCss?: string;
termsUrl?: string;
privacyUrl?: string;
supportEmail?: string;
};
enabledProviders?: AuthProvider[];
providerOrder?: string[];
emailDisplayMode?: 'form' | 'button';
allowedRedirectDomains?: string[];
googleClientId?: string;
googleOAuthFlow?: 'popup' | 'oneTap';
emailBranding?: EmailBrandingConfig;
emailVerification?: {
mode?: EmailVerificationMode;
gracePeriodHours?: number;
requireVerification?: boolean;
};
signupAdditionalFields?: ClaimField[];
}
export interface AuthUser {
uid: string;
email?: string;
displayName?: string;
phoneNumber?: string;
photoURL?: string;
accountData?: Record<string, any>;
}
export interface AuthToken {
token: string;
expiresAt: number;
}
export interface AuthResponse {
token?: string;
user: AuthUser;
accountData?: Record<string, any>;
emailVerificationMode?: EmailVerificationMode;
requiresEmailVerification?: boolean;
emailVerificationDeadline?: number;
accountLocked?: boolean;
}
export interface SmartlinksAuthUIProps {
/** Your Smartlinks API endpoint URL */
apiEndpoint: string;
/** Client ID to identify your system/tenant - REQUIRED */
clientId: string;
/** Client name for branded emails */
clientName?: string;
/** Additional account data to store on registration */
accountData?: Record<string, any>;
/** Callback when authentication succeeds */
onAuthSuccess: (token: string, user: AuthUser, accountData?: Record<string, any>) => void;
/** Callback when authentication fails */
onAuthError?: (error: Error) => void;
/** Auth providers to enable */
enabledProviders?: AuthProvider[];
/**
* Initial mode to display (login or signup form)
* Defaults to 'login'
*/
initialMode?: 'login' | 'register';
/**
* URL to redirect after successful auth, password reset, or email verification.
* Defaults to the current page (including hash routes).
* Example: if not provided and user is on /#/test, emails will redirect to /#/test?mode=verifyEmail&token=...
*/
redirectUrl?: string;
/** UI theme - 'auto' detects system preference */
theme?: 'light' | 'dark' | 'auto';
/** Additional CSS class name */
className?: string;
/** UI customization (overrides API-fetched config) */
customization?: Partial<AuthUIConfig>;
/** Skip fetching config from API (use only props/defaults) */
skipConfigFetch?: boolean;
/** Minimal mode - removes all framing, backgrounds, and borders for embedding */
minimal?: boolean;
/**
* Optional logger for verbose logging. Can be:
* - A console-like object with log/warn/error/debug methods
* - A function that receives all log messages
* When provided, enables verbose logging in both the auth UI and Smartlinks SDK.
* Set to `console` for easy debugging.
*/
logger?: AuthLogger;
}
export type FirebaseAuthUIProps = SmartlinksAuthUIProps;
export interface AuthFormData {
email?: string;
password?: string;
displayName?: string;
phoneNumber?: string;
verificationCode?: string;
clientId?: string;
accountData?: Record<string, any>;
redirectUrl?: string;
}
export type AuthMode = 'login' | 'register' | 'reset-password' | 'verify-email' | 'phone' | 'magic-link';
export interface URLAuthParams {
mode?: 'verifyEmail' | 'resetPassword' | 'recoverEmail' | 'magicLink';
oobCode?: string;
}
export type AuthStateChangeCallback = (event: {
type: 'LOGIN' | 'LOGOUT' | 'TOKEN_REFRESH' | 'CROSS_TAB_SYNC' | 'ACCOUNT_REFRESH';
user: AuthUser | null;
token: string | null;
accountData: Record<string, any> | null;
accountInfo?: Record<string, any> | null;
}) => void;
export interface AuthContextValue {
user: AuthUser | null;
token: string | null;
accountData: Record<string, any> | null;
accountInfo: Record<string, any> | null;
isAuthenticated: boolean;
isLoading: boolean;
smartlinks: any | null;
login: (token: string, user: AuthUser, accountData?: Record<string, any>) => Promise<void>;
logout: () => Promise<void>;
getToken: () => Promise<string | null>;
refreshToken: () => Promise<string>;
getAccount: (forceRefresh?: boolean) => Promise<Record<string, any>>;
refreshAccount: () => Promise<Record<string, any>>;
clearAccountCache: () => Promise<void>;
onAuthStateChange: (callback: AuthStateChangeCallback) => () => void;
}
export interface UserProfile {
uid: string;
email?: string;
displayName?: string;
phoneNumber?: string;
photoURL?: string;
emailVerified?: boolean;
accountData?: Record<string, any>;
createdAt?: string;
}
export interface ProfileUpdateData {
displayName?: string;
photoURL?: string;
accountData?: Record<string, any>;
}
export interface AccountManagementProps {
/** Your Smartlinks API endpoint URL */
apiEndpoint: string;
/** Client ID to identify your system/tenant - REQUIRED */
clientId: string;
/** Callback when profile is updated */
onProfileUpdated?: (profile: UserProfile) => void;
/** Callback when email change is requested */
onEmailChangeRequested?: () => void;
/** Callback when password is changed */
onPasswordChanged?: () => void;
/** Callback when account is deleted */
onAccountDeleted?: () => void;
/** Callback for errors */
onError?: (error: Error) => void;
/** UI theme */
theme?: 'light' | 'dark';
/** Additional CSS class name */
className?: string;
/** Customization options */
customization?: {
showProfileSection?: boolean;
showEmailSection?: boolean;
showPasswordSection?: boolean;
showPhoneSection?: boolean;
showDeleteAccount?: boolean;
};
/** Minimal mode - removes all framing, backgrounds, and borders for embedding */
minimal?: boolean;
}
export interface ClaimField {
name: string;
label: string;
type: 'text' | 'email' | 'phone' | 'select' | 'textarea';
required?: boolean;
options?: string[];
placeholder?: string;
}
export interface ClaimResult {
proofId: string;
user: AuthUser;
claimData: Record<string, any>;
attestationId?: string;
}
export interface SmartlinksClaimUIProps {
/** Your Smartlinks API endpoint URL */
apiEndpoint: string;
/** Client ID to identify your system/tenant - REQUIRED */
clientId: string;
/** Client name for branded emails */
clientName?: string;
/** Collection ID for the proof being claimed */
collectionId: string;
/** Product ID for the proof being claimed */
productId: string;
/** Proof ID to claim */
proofId: string;
/** Callback when claim succeeds */
onClaimSuccess: (claimData: ClaimResult) => void;
/** Callback when claim fails */
onClaimError?: (error: Error) => void;
/** Additional custom fields to collect during claim */
additionalFields?: ClaimField[];
/** UI theme */
theme?: 'light' | 'dark';
/** Additional CSS class name */
className?: string;
/** Minimal mode - removes all framing, backgrounds, and borders for embedding */
minimal?: boolean;
/** Customization options */
customization?: {
claimTitle?: string;
claimDescription?: string;
successMessage?: string;
authConfig?: Partial<AuthUIConfig>;
};
}
//# sourceMappingURL=types.d.ts.map