authrix
Version:
Lightweight, flexible authentication library for Node.js and TypeScript.
209 lines (204 loc) • 6.18 kB
text/typescript
export { a as authConfig, g as getAuthrixStatus, i as initAuth, b as isAuthrixInitialized } from './index-BpFSCakw.cjs';
export { A as AuthDbAdapter, a as AuthUser } from './db-R-GJxQGc.cjs';
interface ForgotPasswordOptions {
codeLength?: number;
codeExpiration?: number;
maxAttempts?: number;
rateLimitDelay?: number;
requireExistingUser?: boolean;
customEmailTemplate?: (email: string, code: string, username?: string) => {
subject: string;
text: string;
html?: string;
};
}
interface ForgotPasswordOptions {
codeLength?: number;
codeExpiration?: number;
maxAttempts?: number;
rateLimitDelay?: number;
requireExistingUser?: boolean;
customEmailTemplate?: (email: string, code: string, username?: string) => {
subject: string;
text: string;
html?: string;
};
}
interface ResetPasswordOptions {
minPasswordLength?: number;
requireStrongPassword?: boolean;
invalidateAllSessions?: boolean;
preventReuse?: boolean;
}
interface ResetPasswordOptions {
minPasswordLength?: number;
requireStrongPassword?: boolean;
invalidateAllSessions?: boolean;
preventReuse?: boolean;
}
interface ForgotPasswordResult {
success: boolean;
message: string;
codeExpiration?: Date;
}
interface ForgotPasswordResult {
success: boolean;
message: string;
codeExpiration?: Date;
}
interface ResetPasswordResult {
success: boolean;
message: string;
user?: {
id: string;
email: string;
username?: string;
};
}
interface ResetPasswordResult {
success: boolean;
message: string;
user?: {
id: string;
email: string;
username?: string;
};
}
/**
* Initiate forgot password process
*/
declare function initiateForgotPassword(email: string, options?: ForgotPasswordOptions): Promise<ForgotPasswordResult>;
/**
* Verify forgot password code and reset password
*/
declare function resetPasswordWithCode(email: string, code: string, newPassword: string, options?: ResetPasswordOptions): Promise<ResetPasswordResult>;
/**
* Generate a secure temporary password
*/
declare function generateTemporaryPassword(length?: number): string;
/**
* Send temporary password to user (alternative to code-based reset)
*/
declare function sendTemporaryPassword(email: string, options?: ForgotPasswordOptions & {
temporaryPasswordLength?: number;
}): Promise<ForgotPasswordResult>;
interface SSOUser {
id: string;
email: string;
name?: string;
firstName?: string;
lastName?: string;
avatar?: string;
provider: string;
verified?: boolean;
locale?: string;
[key: string]: any;
}
interface SSOOptions {
autoCreateUser?: boolean;
updateExistingUser?: boolean;
requireVerifiedEmail?: boolean;
mergeUserData?: boolean;
customUserMapping?: (ssoUser: SSOUser) => Partial<any>;
}
interface SSOResult {
user: {
id: string;
email: string;
username?: string;
firstName?: string;
lastName?: string;
};
token: string;
cookieOptions: {
httpOnly: boolean;
secure: boolean;
maxAge: number;
sameSite: "lax" | "strict" | "none";
path: string;
};
isNewUser: boolean;
provider: string;
}
/**
* Process SSO authentication and create/update user
*/
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>;
/**
* 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;
/**
* Universal SSO helpers that work with any framework
*/
declare const ssoHelpers: {
/**
* Get Google OAuth URL with state
*/
getGoogleAuthUrl(redirectUrl?: string): string;
/**
* Get GitHub OAuth URL with state
*/
getGitHubAuthUrl(redirectUrl?: string): string;
/**
* Handle OAuth callback (works with any provider)
*/
handleCallback(provider: "google" | "github", code: string, state: string, options?: SSOOptions): Promise<{
redirectUrl: any;
user: {
id: string;
email: string;
username?: string;
firstName?: string;
lastName?: string;
};
token: string;
cookieOptions: {
httpOnly: boolean;
secure: boolean;
maxAge: number;
sameSite: "lax" | "strict" | "none";
path: string;
};
isNewUser: boolean;
provider: string;
}>;
/**
* Generate secure state for OAuth
*/
generateState(data?: any): string;
/**
* Verify OAuth state
*/
verifyState(state: string, maxAge?: number): any;
};
/**
* Universal forgot password helpers
*/
declare const forgotPasswordHelpers: {
/**
* Initiate password reset
*/
initiate(email: string, options?: ForgotPasswordOptions): Promise<ForgotPasswordResult>;
/**
* Reset password with verification code
*/
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, handleCustomSSO as b, type SSOOptions as c, type SSOResult as d, forgotPasswordHelpers, generateSSOState as g, generateTemporaryPassword, handleGoogleSSO as h, initiateForgotPassword, processSSOAuthentication as p, resetPasswordWithCode, ssoHelpers as s, sendTemporaryPassword, verifySSOState as v };