diff --git a/frontend/src/routes/auth/about/[id]/+page.server.js b/frontend/src/routes/auth/about/[id]/+page.server.js index 1b8a938..ca9fc67 100644 --- a/frontend/src/routes/auth/about/[id]/+page.server.js +++ b/frontend/src/routes/auth/about/[id]/+page.server.js @@ -90,7 +90,9 @@ export const actions = { console.dir(formData); console.dir(cleanUpdateData); const apiURL = `${BASE_API_URI}/backend/users/update/`; - const res = await fetch(apiURL, { + + /** @type {RequestInit} */ + const requestUpdateOptions = { method: "PATCH", credentials: "include", headers: { @@ -98,11 +100,12 @@ export const actions = { Cookie: `jwt=${cookies.get("jwt")}`, }, body: JSON.stringify(cleanUpdateData), - }); + }; + const res = await fetch(apiURL, requestUpdateOptions); if (!res.ok) { const response = await res.json(); - const errors = formatError(response.error); + const errors = formatError(response.errors); return fail(400, { errors: errors }); } @@ -159,7 +162,7 @@ export const actions = { if (!res.ok) { const response = await res.json(); - const errors = formatError(response.error); + const errors = formatError(response.errors); return fail(400, { errors: errors }); } @@ -195,7 +198,7 @@ export const actions = { if (!res.ok) { const response = await res.json(); - const errors = formatError(response.error); + const errors = formatError(response.errors); return fail(400, { errors: errors }); } diff --git a/frontend/src/routes/auth/about/[id]/+page.svelte b/frontend/src/routes/auth/about/[id]/+page.svelte index 515bf38..bdc4d65 100644 --- a/frontend/src/routes/auth/about/[id]/+page.svelte +++ b/frontend/src/routes/auth/about/[id]/+page.svelte @@ -99,7 +99,12 @@ password2 = ""; const open = () => (showModal = true); - const close = () => (showModal = false); + const close = () => { + showModal = false; + if (form) { + form.errors = undefined; + } + }; // const toggleAvatars = () => (showAvatars = !showAvatars); $: selectedSubscriptionModel = @@ -222,7 +227,7 @@ in:receive={{ key: error.id }} out:send={{ key: error.id }} > - {error.error} + {$t(error.field) + ": " + $t(error.key)} {/each} {/if} diff --git a/frontend/src/routes/auth/login/+page.server.js b/frontend/src/routes/auth/login/+page.server.js index 4cda427..d33d1ef 100644 --- a/frontend/src/routes/auth/login/+page.server.js +++ b/frontend/src/routes/auth/login/+page.server.js @@ -44,18 +44,9 @@ export const actions = { console.log("Login response headers:", Object.fromEntries(res.headers)); if (!res.ok) { - let errorMessage = `HTTP error! status: ${res.status}`; - try { - const errorData = await res.json(); - errorMessage = errorData.error || errorMessage; - } catch (parseError) { - console.error("Failed to parse error response:", parseError); - errorMessage = await res.text(); // Get the raw response text if JSON parsing fails - } - console.error("Login failed:", errorMessage); - return fail(res.status, { - errors: [{ error: errorMessage, id: Date.now() }], - }); + const errorData = await res.json(); + const errors = formatError(errorData.errors); + return fail(res.status, { errors }); } const responseBody = await res.json(); @@ -81,12 +72,4 @@ export const actions = { console.log("Redirecting to:", next || "/"); throw redirect(303, next || "/"); }, - // if (!res.ok) { - // const response = await res.json(); - // const errors = formatError(response.error); - // return fail(400, { errors: errors }); - // } - - // throw redirect(303, next || "/"); - // }, }; diff --git a/frontend/src/routes/auth/login/+page.svelte b/frontend/src/routes/auth/login/+page.svelte index fd595ad..fe67b72 100644 --- a/frontend/src/routes/auth/login/+page.svelte +++ b/frontend/src/routes/auth/login/+page.svelte @@ -35,7 +35,7 @@ in:receive={{ key: error.id }} out:send={{ key: error.id }} > - {error.error} + {$t(error.key)} {/each} {/if}