UNPKG

authrix

Version:

Lightweight, flexible authentication library for Node.js and TypeScript.

206 lines (201 loc) 7.66 kB
export { a as authConfig, g as getAuthrixStatus, i as initAuth, b as isAuthrixInitialized } from './index-2c4aN9k6.js'; export { A as AuthDbAdapter, a as AuthUser } from './db-BIgxMgj8.js'; interface ForgotPasswordOptions { codeLength?: number; codeExpiration?: number; maxAttempts?: number; rateLimitDelay?: number; requireExistingUser?: boolean; useEmailService?: boolean; customEmailTemplate?: (email: string, code: string, username?: string) => { subject: string; text: string; html?: string; }; } interface ResetPasswordOptions { minPasswordLength?: number; requireStrongPassword?: boolean; invalidateAllSessions?: boolean; preventReuse?: boolean; skipPasswordValidation?: boolean; } interface ForgotPasswordResult { success: boolean; message: string; codeId?: string; codeExpiration?: Date; attemptsRemaining?: number; } interface ResetPasswordResult { success: boolean; message: string; user?: { id: string; email: string; username?: string; }; mustChangePassword?: boolean; } /** * Enhanced forgot password initiation with 2FA integration */ declare function initiateForgotPassword(email: string, options?: ForgotPasswordOptions): Promise<ForgotPasswordResult>; /** * Enhanced password reset with improved validation and security */ declare function resetPasswordWithCode(email: string, code: string, newPassword: string, options?: ResetPasswordOptions): Promise<ResetPasswordResult>; /** * Enhanced temporary password generation with better security */ declare function generateTemporaryPassword(length?: number): string; /** * Enhanced temporary password sending with 2FA integration */ declare function sendTemporaryPassword(email: string, options?: ForgotPasswordOptions & { temporaryPasswordLength?: number; }): Promise<ForgotPasswordResult>; /** * Normalized SSO user profile as returned by provider callbacks. */ interface SSOUser { id: string; email: string; name?: string; firstName?: string; lastName?: string; fullName?: string; avatar?: string; provider: string; verified?: boolean; locale?: string; [key: string]: any; } /** Options controlling SSO account handling and merging */ interface SSOOptions { autoCreateUser?: boolean; updateExistingUser?: boolean; requireVerifiedEmail?: boolean; mergeUserData?: boolean; customUserMapping?: (ssoUser: SSOUser) => Partial<any>; } /** Result of a completed SSO authentication */ interface SSOResult { user: { id: string; email: string; username?: string; firstName?: string; lastName?: string; fullName?: string; profilePicture?: string; }; token: string; cookieOptions: { httpOnly: boolean; secure: boolean; maxAge: number; sameSite: "lax" | "strict" | "none"; path: string; }; isNewUser: boolean; provider: string; } /** Orchestrates SSO auth: finds/creates user, merges minimal profile, and returns JWT. */ declare function processSSOAuthentication(ssoUser: SSOUser, options?: SSOOptions): Promise<SSOResult>; /** * Handle Google OAuth authentication */ declare function handleGoogleSSO(code: string, options?: SSOOptions): Promise<SSOResult>; /** * Handle GitHub OAuth authentication */ declare function handleGitHubSSO(code: string, options?: SSOOptions): Promise<SSOResult>; /** * Handle Apple OAuth authentication */ declare function handleAppleSSO(code: string, options?: SSOOptions): Promise<SSOResult>; /** * Handle Discord OAuth authentication */ declare function handleDiscordSSO(code: string, options?: SSOOptions): Promise<SSOResult>; /** * Handle Facebook OAuth authentication */ declare function handleFacebookSSO(code: string, options?: SSOOptions): Promise<SSOResult>; /** * Handle LinkedIn OAuth authentication */ declare function handleLinkedInSSO(code: string, options?: SSOOptions): Promise<SSOResult>; /** * Handle X/Twitter OAuth authentication */ declare function handleXSSO(code: string, state: string, options?: SSOOptions): Promise<SSOResult>; /** * Generic SSO handler for custom providers */ declare function handleCustomSSO(provider: string, userData: SSOUser, options?: SSOOptions): Promise<SSOResult>; /** * Generate SSO state parameter for security */ declare function generateSSOState(data?: any): string; /** * Verify SSO state parameter */ declare function verifySSOState(state: string, maxAge?: number): any; type SupportedProvider = 'google' | 'github' | 'apple' | 'discord' | 'facebook' | 'linkedin' | 'x'; declare function buildProviderAuthUrl(provider: SupportedProvider, redirectUrl?: string): Promise<string> | string; declare function getGoogleAuthUrl(redirectUrl?: string): string | Promise<string>; declare function getGitHubAuthUrl(redirectUrl?: string): string | Promise<string>; declare function getAppleAuthUrl(redirectUrl?: string): string | Promise<string>; declare function getDiscordAuthUrl(redirectUrl?: string): string | Promise<string>; declare function getFacebookAuthUrl(redirectUrl?: string): string | Promise<string>; declare function getLinkedInAuthUrl(redirectUrl?: string): string | Promise<string>; declare function getXAuthUrl(redirectUrl?: string): string | Promise<string>; declare function getAllAuthUrls(redirectUrl?: string, providers?: SupportedProvider[]): Promise<Record<SupportedProvider, string>>; /** * Universal SSO helpers that work with any framework */ declare const ssoHelpers: { getGoogleAuthUrl: typeof getGoogleAuthUrl; getGitHubAuthUrl: typeof getGitHubAuthUrl; getAppleAuthUrl: typeof getAppleAuthUrl; getDiscordAuthUrl: typeof getDiscordAuthUrl; getFacebookAuthUrl: typeof getFacebookAuthUrl; getLinkedInAuthUrl: typeof getLinkedInAuthUrl; getXAuthUrl: typeof getXAuthUrl; buildProviderAuthUrl: typeof buildProviderAuthUrl; getAllAuthUrls: typeof getAllAuthUrls; handleCallback(provider: SupportedProvider, code: string, state: string, options?: SSOOptions): Promise<{ redirectUrl: any; user: { id: string; email: string; username?: string; firstName?: string; lastName?: string; fullName?: string; profilePicture?: string; }; token: string; cookieOptions: { httpOnly: boolean; secure: boolean; maxAge: number; sameSite: "lax" | "strict" | "none"; path: string; }; isNewUser: boolean; provider: string; }>; generateState: (data?: any) => string; verifyState: (state: string, maxAge?: number) => any; }; /** * Universal forgot password helpers */ declare const forgotPasswordHelpers: { initiate: (email: string, options?: ForgotPasswordOptions) => Promise<ForgotPasswordResult>; reset: (email: string, code: string, newPassword: string, options?: ResetPasswordOptions) => Promise<ResetPasswordResult>; }; export { type ForgotPasswordOptions, type ForgotPasswordResult, type ResetPasswordOptions, type ResetPasswordResult, type SSOUser as S, handleGitHubSSO as a, handleAppleSSO as b, handleDiscordSSO as c, handleFacebookSSO as d, handleLinkedInSSO as e, handleXSSO as f, forgotPasswordHelpers, handleCustomSSO as g, generateTemporaryPassword, handleGoogleSSO as h, generateSSOState as i, initiateForgotPassword, type SSOOptions as j, type SSOResult as k, processSSOAuthentication as p, resetPasswordWithCode, ssoHelpers as s, sendTemporaryPassword, verifySSOState as v };