// File: frontend/src/api/services/authService.ts import { tokenManager } from '../auth/tokenManager'; import { apiClient } from '../base/apiClient'; export interface LoginCredentials { email: string; password: string; } export interface RegisterData { email: string; password: string; full_name: string; tenant_name?: string; } export interface UserProfile { id: string; email: string; full_name: string; tenant_id: string; role: string; is_active: boolean; created_at: string; } class AuthService { async login(credentials: LoginCredentials): Promise { // FIXED: Use correct endpoint and method const response = await apiClient.post('/api/v1/auth/login', credentials); // Store tokens from login response await tokenManager.storeTokens(response); // Get user profile from the response or make separate call if (response.user) { return response.user; } else { return this.getCurrentUser(); } } async register(data: RegisterData): Promise { // FIXED: Use correct endpoint path const response = await apiClient.post('/api/v1/auth/register', data); // Registration only returns user data, NOT tokens // So we need to login separately to get tokens await this.login({ email: data.email, password: data.password }); return response; // This is the user profile from registration } async logout(): Promise { try { await apiClient.post('/api/v1/auth/logout'); } finally { tokenManager.clearTokens(); window.location.href = '/login'; } } async getCurrentUser(): Promise { return apiClient.get('/api/v1/auth/me'); } async updateProfile(updates: Partial): Promise { return apiClient.patch('/api/v1/auth/profile', updates); } async changePassword(currentPassword: string, newPassword: string): Promise { await apiClient.post('/api/v1/auth/change-password', { current_password: currentPassword, new_password: newPassword }); } isAuthenticated(): boolean { return tokenManager.isAuthenticated(); } } export const authService = new AuthService();