authrix
Version:
Lightweight, flexible authentication library for Node.js and TypeScript.
50 lines (48 loc) • 1.53 kB
text/typescript
interface AuthUser {
id: string;
email: string;
username?: string;
firstName?: string;
lastName?: string;
password: string;
createdAt?: Date;
emailVerified?: boolean;
emailVerifiedAt?: Date;
twoFactorEnabled?: boolean;
[key: string]: any;
}
interface TwoFactorCode {
id: string;
userId: string;
code: string;
hashedCode: string;
type: 'email_verification' | 'password_reset' | 'login_verification';
expiresAt: Date;
createdAt: Date;
attempts: number;
isUsed: boolean;
metadata?: {
email?: string;
ipAddress?: string;
userAgent?: string;
};
}
interface AuthDbAdapter {
findUserByEmail(email: string): Promise<AuthUser | null>;
findUserById(id: string): Promise<AuthUser | null>;
findUserByUsername(username: string): Promise<AuthUser | null>;
createUser(data: {
email: string;
password: string;
username?: string;
firstName?: string;
lastName?: string;
}): Promise<AuthUser>;
updateUser?(id: string, data: Partial<AuthUser>): Promise<AuthUser>;
storeTwoFactorCode?(code: TwoFactorCode): Promise<void>;
getTwoFactorCode?(codeId: string): Promise<TwoFactorCode | null>;
updateTwoFactorCode?(codeId: string, updates: Partial<TwoFactorCode>): Promise<void>;
getUserTwoFactorCodes?(userId: string, type?: string): Promise<TwoFactorCode[]>;
cleanupExpiredTwoFactorCodes?(): Promise<number>;
}
export type { AuthDbAdapter as A, AuthUser as a };