Add new frontend - fix 12
This commit is contained in:
@@ -320,5 +320,5 @@ class ApiClient {
|
||||
|
||||
// FIXED: Create default instance with correct base URL (removed /api suffix)
|
||||
export const apiClient = new ApiClient({
|
||||
baseURL: process.env.REACT_APP_API_URL || 'http://localhost:8000'
|
||||
baseURL: process.env.FRONTEND_API_URL || 'http://localhost:8000/api/v1'
|
||||
});
|
||||
@@ -1,5 +1,6 @@
|
||||
// src/api/services/AuthService.ts
|
||||
// src/api/services/AuthService.ts - UPDATED with missing methods
|
||||
import { apiClient } from '../base/apiClient';
|
||||
import { tokenManager } from '../auth/tokenManager';
|
||||
import {
|
||||
ApiResponse,
|
||||
LoginRequest,
|
||||
@@ -9,6 +10,27 @@ import {
|
||||
} from '../types/api';
|
||||
|
||||
export class AuthService {
|
||||
/**
|
||||
* Check if user is authenticated (has valid token)
|
||||
* Note: This is a synchronous check using the tokenManager's isAuthenticated method
|
||||
*/
|
||||
isAuthenticated(): boolean {
|
||||
try {
|
||||
return tokenManager.isAuthenticated();
|
||||
} catch (error) {
|
||||
console.error('Error checking authentication status:', error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current user profile
|
||||
*/
|
||||
async getCurrentUser(): Promise<UserProfile> {
|
||||
const response = await apiClient.get<ApiResponse<UserProfile>>('/users/me');
|
||||
return response.data!;
|
||||
}
|
||||
|
||||
/**
|
||||
* User login
|
||||
*/
|
||||
@@ -17,7 +39,12 @@ export class AuthService {
|
||||
'/auth/login',
|
||||
credentials
|
||||
);
|
||||
return response.data!;
|
||||
|
||||
// Store tokens after successful login
|
||||
const tokenData = response.data!;
|
||||
await tokenManager.storeTokens(tokenData);
|
||||
|
||||
return tokenData;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,11 +70,10 @@ export class AuthService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current user profile
|
||||
* Get current user profile (alias for getCurrentUser)
|
||||
*/
|
||||
async getProfile(): Promise<UserProfile> {
|
||||
const response = await apiClient.get<ApiResponse<UserProfile>>('/users/me');
|
||||
return response.data!;
|
||||
return this.getCurrentUser();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,7 +138,14 @@ export class AuthService {
|
||||
* Logout (invalidate tokens)
|
||||
*/
|
||||
async logout(): Promise<void> {
|
||||
await apiClient.post('/auth/logout');
|
||||
try {
|
||||
await apiClient.post('/auth/logout');
|
||||
} catch (error) {
|
||||
console.error('Logout API call failed:', error);
|
||||
} finally {
|
||||
// Always clear tokens regardless of API call success
|
||||
tokenManager.clearTokens();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
*/
|
||||
|
||||
// Import all service classes
|
||||
export { AuthService, authService } from './authService';
|
||||
export { DataService, dataService } from './dataService';
|
||||
export { TrainingService, trainingService } from './trainingService';
|
||||
export { ForecastingService, forecastingService } from './forecastingService';
|
||||
export { NotificationService, notificationService } from './notificationService';
|
||||
export { TenantService, tenantService } from './tenantService';
|
||||
import { AuthService, authService } from './authService';
|
||||
import { DataService, dataService } from './dataService';
|
||||
import { TrainingService, trainingService } from './trainingService';
|
||||
import { ForecastingService, forecastingService } from './forecastingService';
|
||||
import { NotificationService, notificationService } from './notificationService';
|
||||
import { TenantService, tenantService } from './tenantService';
|
||||
|
||||
// Import base API client for custom implementations
|
||||
export { apiClient } from '../base/apiClient';
|
||||
|
||||
Reference in New Issue
Block a user