// frontend/src/api/services/auth.service.ts /** * Authentication Service * Handles all authentication-related API calls */ import { apiClient } from '../client'; import { serviceEndpoints } from '../client/config'; import type { LoginRequest, LoginResponse, RegisterRequest, UserResponse, PasswordResetRequest, PasswordResetResponse, PasswordResetConfirmRequest, TokenVerification, LogoutResponse, } from '../types'; export class AuthService { private baseEndpoint = serviceEndpoints.auth; /** * User Registration */ async register(data: RegisterRequest): Promise<{ user: UserResponse }> { return apiClient.post(`${this.baseEndpoint}/register`, data); } /** * User Login */ async login(credentials: LoginRequest): Promise { return apiClient.post(`${this.baseEndpoint}/login`, credentials); } /** * User Logout */ async logout(): Promise { return apiClient.post(`${this.baseEndpoint}/logout`); } /** * Get Current User Profile */ async getCurrentUser(): Promise { return apiClient.get(`/users/me`); } /** * Update User Profile */ async updateProfile(data: Partial): Promise { return apiClient.put(`/users/me`, data); } /** * Verify Token */ async verifyToken(token: string): Promise { return apiClient.post(`${this.baseEndpoint}/verify-token`, { token }); } /** * Refresh Access Token */ async refreshToken(refreshToken: string): Promise { return apiClient.post(`${this.baseEndpoint}/refresh`, { refresh_token: refreshToken, }); } /** * Request Password Reset */ async requestPasswordReset(data: PasswordResetRequest): Promise { return apiClient.post(`${this.baseEndpoint}/password-reset`, data); } /** * Confirm Password Reset */ async confirmPasswordReset(data: PasswordResetConfirmRequest): Promise<{ message: string }> { return apiClient.post(`${this.baseEndpoint}/password-reset/confirm`, data); } /** * Change Password (for authenticated users) */ async changePassword(currentPassword: string, newPassword: string): Promise<{ message: string }> { return apiClient.post(`/users/me/change-password`, { current_password: currentPassword, new_password: newPassword, }); } /** * Delete User Account */ async deleteAccount(): Promise<{ message: string }> { return apiClient.delete(`/users/me`); } } export const authService = new AuthService();