diff options
Diffstat (limited to 'src/routes/(static)')
| -rw-r--r-- | src/routes/(static)/login/+page.server.ts | 9 | ||||
| -rw-r--r-- | src/routes/(static)/register/+page.server.ts | 3 |
2 files changed, 8 insertions, 4 deletions
diff --git a/src/routes/(static)/login/+page.server.ts b/src/routes/(static)/login/+page.server.ts index d81f2ccb..6c82a209 100644 --- a/src/routes/(static)/login/+page.server.ts +++ b/src/routes/(static)/login/+page.server.ts @@ -25,7 +25,7 @@ export const actions = { if (loginRedirect === "undefined") loginRedirect = undefined; try { - await login(user, cookies, request.headers.get("cf-connecting-ip")); + await login(user, cookies, request.headers.get("cf-connecting-ip"), request.headers.get("host")); } catch (e) { const { message } = e as Error; return fail(400, { error: "Login failed", message, ...form }); @@ -49,15 +49,18 @@ export const actions = { "content-type": "application/json", accept: "application/json", "cf-connecting-ip": request.headers.get("cf-connecting-ip"), + host: request.headers.get("host"), }, }); + const text = await res.text(); + if (res.status === 401) { - const text = await res.text(); if (text.startsWith("2fa")) throw new Error("2fa"); + throw new Error(text); } - const { user, token } = await res.json(); + const { user, token } = JSON.parse(text); if (!token) throw new Error("Login failed"); const { username, language } = user; diff --git a/src/routes/(static)/register/+page.server.ts b/src/routes/(static)/register/+page.server.ts index d2dbe299..2bcf6f2d 100644 --- a/src/routes/(static)/register/+page.server.ts +++ b/src/routes/(static)/register/+page.server.ts @@ -14,12 +14,13 @@ export const load = async ({ parent }) => { export const actions = { default: async ({ cookies, request }) => { const ip = request.headers.get("cf-connecting-ip"); + const host = request.headers.get("host"); const form = await fd(request); const { picture, username, password, challenge, recaptcha } = form; let { loginRedirect } = form; if (loginRedirect === "undefined") loginRedirect = undefined; const user = { picture, username, password, challenge, recaptcha }; - return register(user, ip, cookies, loginRedirect); + return register(user, ip, cookies, loginRedirect, host); }, }; |
