diff --git a/frontend/src/lib/api.js b/frontend/src/lib/api.js index d021c00..afa967c 100644 --- a/frontend/src/lib/api.js +++ b/frontend/src/lib/api.js @@ -43,8 +43,12 @@ class ApiClient { } if (!response.ok) { - const error = await response.json().catch(() => ({ detail: 'Request failed' })); - throw new Error(error.detail || 'Request failed'); + const errorData = await response.json().catch(() => ({ detail: 'Request failed' })); + // Handle FastAPI validation errors + if (errorData.detail && typeof errorData.detail === 'object') { + throw new Error(JSON.stringify(errorData.detail)); + } + throw new Error(errorData.detail || 'Request failed'); } if (response.status === 204) { @@ -55,10 +59,31 @@ class ApiClient { } async login(email, password) { - const data = await this.request('/auth/login', { + const response = await fetch(`${API_BASE}/auth/login`, { method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, body: JSON.stringify({ email, password }), }); + + const data = await response.json().catch(() => ({})); + + if (!response.ok) { + if (data.detail) { + if (typeof data.detail === 'string') { + throw new Error(data.detail); + } + // Validation errors + if (Array.isArray(data.detail)) { + const messages = data.detail.map(e => e.msg).join(', '); + throw new Error(messages); + } + throw new Error(JSON.stringify(data.detail)); + } + throw new Error('Login failed'); + } + this.setToken(data.access_token); return data; } diff --git a/frontend/src/routes/login/+page.svelte b/frontend/src/routes/login/+page.svelte index 5b3f8e0..00872a1 100644 --- a/frontend/src/routes/login/+page.svelte +++ b/frontend/src/routes/login/+page.svelte @@ -82,7 +82,7 @@
Demo Admin:
-Email: admin@moxiegen.local
+Email: admin@moxiegen.com
Password: admin123