From dd05f3a0f5f502ef15f9df6f7c92610ef6c1ccdf Mon Sep 17 00:00:00 2001 From: Urtzi Alfaro Date: Tue, 22 Jul 2025 20:22:27 +0200 Subject: [PATCH] Add new frontend - fix 13 --- docker-compose.yml | 4 ++++ frontend/src/api/base/apiClient.ts | 2 +- frontend/src/api/services/authService.ts | 12 +++++++++--- frontend/src/api/websocket/WebSocketManager.ts | 4 ++-- frontend/src/contexts/AuthContext.tsx | 6 +++++- 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 9b62bfe9..36bacf2e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -591,6 +591,10 @@ services: build: context: ./frontend dockerfile: Dockerfile.${ENVIRONMENT} + args: + - REACT_APP_API_URL=${FRONTEND_API_URL} + - REACT_APP_WS_URL=${FRONTEND_WS_URL} + - REACT_APP_ENVIRONMENT=${ENVIRONMENT} image: bakery/dashboard:${IMAGE_TAG} container_name: bakery-dashboard restart: unless-stopped diff --git a/frontend/src/api/base/apiClient.ts b/frontend/src/api/base/apiClient.ts index d15c1a7e..eca97c19 100644 --- a/frontend/src/api/base/apiClient.ts +++ b/frontend/src/api/base/apiClient.ts @@ -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.FRONTEND_API_URL || 'http://localhost:8000/api/v1' + baseURL: process.env.REACT_APP_API_URL || 'http://localhost:8000/api/v1' }); \ No newline at end of file diff --git a/frontend/src/api/services/authService.ts b/frontend/src/api/services/authService.ts index 8ea6e1ba..6b059784 100644 --- a/frontend/src/api/services/authService.ts +++ b/frontend/src/api/services/authService.ts @@ -50,14 +50,20 @@ export class AuthService { /** * User registration */ - async register(userData: RegisterRequest): Promise { - const response = await apiClient.post>( + async register(userData: RegisterRequest): Promise { + const response = await apiClient.post>( '/auth/register', userData ); - return response.data!; + + // Store tokens after successful registration + const tokenData = response.data!; + await tokenManager.storeTokens(tokenData); + + return tokenData; } + /** * Refresh access token */ diff --git a/frontend/src/api/websocket/WebSocketManager.ts b/frontend/src/api/websocket/WebSocketManager.ts index 58ce8af2..06cf8c6e 100644 --- a/frontend/src/api/websocket/WebSocketManager.ts +++ b/frontend/src/api/websocket/WebSocketManager.ts @@ -216,13 +216,13 @@ class WebSocketManager extends EventEmitter { private getWebSocketBaseUrl(): string { if (typeof window !== 'undefined') { // Check if window is defined const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'; - const host = process.env.FRONTEND_WS_URL || window.location.host; + const host = process.env.REACT_APP_WS_URL || window.location.host; return `${protocol}//${host}/ws`; } else { // Provide a fallback for server-side or non-browser environments // You might want to get this from environment variables or a config file // depending on your setup. - return process.env.FRONTEND_WS_URL || 'ws://localhost:3000/ws'; + return process.env.REACT_APP_WS_URL || 'ws://localhost:3000/ws'; } } diff --git a/frontend/src/contexts/AuthContext.tsx b/frontend/src/contexts/AuthContext.tsx index 57c45945..61d4636f 100644 --- a/frontend/src/contexts/AuthContext.tsx +++ b/frontend/src/contexts/AuthContext.tsx @@ -97,7 +97,11 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children const register = useCallback(async (data: RegisterRequest) => { setIsLoading(true); try { - const profile = await authService.register(data); + // Register and store tokens (like login) + const tokenResponse = await authService.register(data); + + // After registration, get user profile + const profile = await api.auth.getCurrentUser(); setUser(profile); } catch (error) { setIsLoading(false);