Add new frontend - fix 13
This commit is contained in:
@@ -591,6 +591,10 @@ services:
|
|||||||
build:
|
build:
|
||||||
context: ./frontend
|
context: ./frontend
|
||||||
dockerfile: Dockerfile.${ENVIRONMENT}
|
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}
|
image: bakery/dashboard:${IMAGE_TAG}
|
||||||
container_name: bakery-dashboard
|
container_name: bakery-dashboard
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|||||||
@@ -320,5 +320,5 @@ class ApiClient {
|
|||||||
|
|
||||||
// FIXED: Create default instance with correct base URL (removed /api suffix)
|
// FIXED: Create default instance with correct base URL (removed /api suffix)
|
||||||
export const apiClient = new ApiClient({
|
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'
|
||||||
});
|
});
|
||||||
@@ -50,14 +50,20 @@ export class AuthService {
|
|||||||
/**
|
/**
|
||||||
* User registration
|
* User registration
|
||||||
*/
|
*/
|
||||||
async register(userData: RegisterRequest): Promise<UserProfile> {
|
async register(userData: RegisterRequest): Promise<TokenResponse> {
|
||||||
const response = await apiClient.post<ApiResponse<UserProfile>>(
|
const response = await apiClient.post<ApiResponse<TokenResponse>>(
|
||||||
'/auth/register',
|
'/auth/register',
|
||||||
userData
|
userData
|
||||||
);
|
);
|
||||||
return response.data!;
|
|
||||||
|
// Store tokens after successful registration
|
||||||
|
const tokenData = response.data!;
|
||||||
|
await tokenManager.storeTokens(tokenData);
|
||||||
|
|
||||||
|
return tokenData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Refresh access token
|
* Refresh access token
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -216,13 +216,13 @@ class WebSocketManager extends EventEmitter {
|
|||||||
private getWebSocketBaseUrl(): string {
|
private getWebSocketBaseUrl(): string {
|
||||||
if (typeof window !== 'undefined') { // Check if window is defined
|
if (typeof window !== 'undefined') { // Check if window is defined
|
||||||
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
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`;
|
return `${protocol}//${host}/ws`;
|
||||||
} else {
|
} else {
|
||||||
// Provide a fallback for server-side or non-browser environments
|
// Provide a fallback for server-side or non-browser environments
|
||||||
// You might want to get this from environment variables or a config file
|
// You might want to get this from environment variables or a config file
|
||||||
// depending on your setup.
|
// 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';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -97,7 +97,11 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
|||||||
const register = useCallback(async (data: RegisterRequest) => {
|
const register = useCallback(async (data: RegisterRequest) => {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
try {
|
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);
|
setUser(profile);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user