diff --git a/packages/shared-auth/src/core/authService.ts b/packages/shared-auth/src/core/authService.ts index 14da45f77..761e0a722 100644 --- a/packages/shared-auth/src/core/authService.ts +++ b/packages/shared-auth/src/core/authService.ts @@ -1,5 +1,6 @@ import type { AuthServiceConfig, + AuthServiceInterface, AuthEndpoints, AuthResult, TokenRefreshResult, @@ -68,7 +69,7 @@ const DEFAULT_ENDPOINTS: AuthEndpoints = { /** * Create an authentication service with the given configuration */ -export function createAuthService(config: AuthServiceConfig) { +export function createAuthService(config: AuthServiceConfig): AuthServiceInterface { const baseUrl = config.baseUrl.replace(/\/$/, ''); // Remove trailing slash const storageKeys: StorageKeys = { ...DEFAULT_STORAGE_KEYS, ...config.storageKeys }; const endpoints: AuthEndpoints = { ...DEFAULT_ENDPOINTS, ...config.endpoints }; @@ -1174,6 +1175,7 @@ export function createAuthService(config: AuthServiceConfig) { } /** - * Type for the auth service instance + * Type for the auth service instance. + * Uses the explicit interface instead of ReturnType<> to avoid TS inference truncation. */ -export type AuthService = ReturnType; +export type AuthService = AuthServiceInterface; diff --git a/packages/shared-auth/src/types/index.ts b/packages/shared-auth/src/types/index.ts index 4cd551546..2f8f9f467 100644 --- a/packages/shared-auth/src/types/index.ts +++ b/packages/shared-auth/src/types/index.ts @@ -183,3 +183,77 @@ export interface B2BInfo { plan?: string; role?: string; } + +/** + * Explicit interface for the auth service. + * + * TypeScript's ReturnType<> inference truncates large object literals (~27 methods shown). + * This explicit interface ensures all 37 methods are visible to consumers. + */ +export interface AuthServiceInterface { + // Core auth + signIn(email: string, password: string): Promise; + signUp(email: string, password: string, sourceAppUrl?: string): Promise; + signOut(): Promise; + forgotPassword(email: string, redirectTo?: string): Promise; + resetPassword(token: string, newPassword: string): Promise; + resendVerificationEmail(email: string, sourceAppUrl?: string): Promise; + refreshTokens(currentRefreshToken: string): Promise; + changePassword(currentPassword: string, newPassword: string): Promise; + + // Magic link + sendMagicLink(email: string): Promise; + + // Passkeys + isPasskeyAvailable(): boolean; + registerPasskey(friendlyName?: string): Promise; + signInWithPasskey(): Promise; + listPasskeys(): Promise; + deletePasskey(passkeyId: string): Promise; + renamePasskey(passkeyId: string, friendlyName: string): Promise; + + // Two-factor auth + enableTwoFactor( + password: string + ): Promise<{ success: boolean; uri?: string; backupCodes?: string[]; error?: string }>; + disableTwoFactor(password: string): Promise; + verifyTwoFactor(code: string, trustDevice?: boolean): Promise; + verifyBackupCode(code: string): Promise; + generateBackupCodes( + password: string + ): Promise<{ success: boolean; backupCodes?: string[]; error?: string }>; + + // Security + getSecurityEvents(limit?: number): Promise; + listSessions(): Promise; + revokeSession(sessionId: string): Promise; + + // Token management + getAppToken(): Promise; + getRefreshToken(): Promise; + updateTokens(appToken: string, refreshToken: string): Promise; + getUserFromToken(): Promise; + clearAuthStorage(): Promise; + isAuthenticated(): Promise; + + // Credits & B2B + getUserCredits(): Promise; + isB2BUser(): Promise; + getB2BInfo(): Promise; + shouldDisableRevenueCat(): Promise; + getAppSettings(): Promise | null>; + + // SSO + trySSO(): Promise; + + // Utilities + getBaseUrl(): string; + getStorageKeys(): StorageKeys; + onTokenRefresh: ((userData: UserData) => void) | null; + + // Token utilities + isTokenValidLocally(token: string): boolean; + + // Internal + handleAuthError(status: number, errorData: any): AuthResult; +}