UNPKG

@j2blasco/ts-auth

Version:

TypeScript authentication abstraction library that eliminates vendor lock-in and provides mock-free testing for both frontend and backend authentication systems

37 lines (36 loc) 1.77 kB
import { Observable } from 'rxjs'; import { ErrorWithCode, ErrorUnknown, Result, SuccessVoid } from '@j2blasco/ts-result'; import { IAuth, BackendAuthUser, UserId } from '../../core/auth.interface'; /** * A testing implementation of IAuth for testing purposes. * This implementation simulates real authentication behavior without external dependencies. */ export declare class AuthTesting implements IAuth { private users; private currentUser; private authState; private passwordResetTokens; private rateLimitTracker; private idTokens; constructor(); get authState$(): Observable<BackendAuthUser | null | undefined>; signInWithEmailAndPassword(args: { email: string; password: string; persistent: boolean; }): Promise<Result<SuccessVoid, ErrorWithCode<'invalid-email'> | ErrorWithCode<'user-not-found'> | ErrorWithCode<'wrong-password'> | ErrorUnknown>>; getIdToken(): Promise<string>; signOut(): Promise<void>; isEmailAvailable(email: string): Promise<boolean>; changeEmail(email: string): Promise<Result<void, ErrorWithCode<'email-not-available'> | ErrorUnknown>>; triggerResetPasswordFlow(email: string): Promise<Result<SuccessVoid, ErrorWithCode<'rate-limit-exceeded'> | ErrorWithCode<'email-not-in-database'> | ErrorUnknown>>; requestChangePassword(args: { passwordToken: string; newPassword: string; }): Promise<Result<SuccessVoid, ErrorWithCode<'token-expired'> | ErrorWithCode<'token-not-found'> | ErrorUnknown>>; deleteAccount(): Promise<void>; signUp(email: string, password: string): Promise<UserId>; addTestUser(email: string, password: string, uid?: string): UserId; getPasswordResetTokens(): string[]; private isValidEmail; }