/** * Auth Service * * Orchestrates authentication operations. * Calls AuthApiClient for API calls. */ import { AuthApiClient } from '@/lib/api/auth/AuthApiClient'; import { SessionViewModel } from '@/lib/view-models/SessionViewModel'; import { AuthSessionDTO } from '@/lib/types/generated/AuthSessionDTO'; import { LoginParamsDTO } from '@/lib/types/generated/LoginParamsDTO'; import { SignupParamsDTO } from '@/lib/types/generated/SignupParamsDTO'; import { ForgotPasswordDTO } from '@/lib/types/generated/ForgotPasswordDTO'; import { ResetPasswordDTO } from '@/lib/types/generated/ResetPasswordDTO'; import { ConsoleLogger } from '@/lib/infrastructure/logging/ConsoleLogger'; import { EnhancedErrorReporter } from '@/lib/infrastructure/EnhancedErrorReporter'; export class AuthService { private apiClient: AuthApiClient; constructor() { const baseUrl = process.env.NEXT_PUBLIC_API_BASE_URL || 'http://localhost:3001'; const logger = new ConsoleLogger(); const errorReporter = new EnhancedErrorReporter(logger, { showUserNotifications: false, logToConsole: true, reportToExternal: process.env.NODE_ENV === 'production', }); this.apiClient = new AuthApiClient(baseUrl, errorReporter, logger); } async login(params: LoginParamsDTO): Promise { const dto = await this.apiClient.login(params); return new SessionViewModel(dto.user); } async signup(params: SignupParamsDTO): Promise { const dto = await this.apiClient.signup(params); return new SessionViewModel(dto.user); } async logout(): Promise { await this.apiClient.logout(); } async forgotPassword(params: ForgotPasswordDTO): Promise<{ message: string; magicLink?: string }> { return await this.apiClient.forgotPassword(params); } async resetPassword(params: ResetPasswordDTO): Promise<{ message: string }> { return await this.apiClient.resetPassword(params); } }