aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-02-06 17:22:01 +0000
committerAdam Soltys <[email protected]>2026-02-06 17:22:01 +0000
commit8ec5dda44f4676a2e5dae609792710b0719cec43 (patch)
treeb018ac129dce268ffd0f355f379c1be0f693a1e9 /src/lib
parentc9a73999ba678955a3017c4d8442ec4e0b60a0d1 (diff)
downloadcoinos-ui-8ec5dda44f4676a2e5dae609792710b0719cec43.tar.gz
coinos-ui-8ec5dda44f4676a2e5dae609792710b0719cec43.zip
fix tor login
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/utils.ts25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/lib/utils.ts b/src/lib/utils.ts
index b981a4d4..bc5df67a 100644
--- a/src/lib/utils.ts
+++ b/src/lib/utils.ts
@@ -169,24 +169,31 @@ export const login = async (
},
cookies,
ip: string,
+ host?: string,
) => {
const maxAge = 380 * 24 * 60 * 60;
+ const headers: Record<string, string> = {
+ "content-type": "application/json",
+ accept: "application/json",
+ "cf-connecting-ip": ip,
+ };
+ if (host) headers["host"] = host;
+
const res = await fetch(`${base}/login`, {
method: "POST",
body: JSON.stringify(user),
- headers: {
- "content-type": "application/json",
- accept: "application/json",
- "cf-connecting-ip": ip,
- },
+ headers,
});
+
+ 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: u, token } = await res.json();
+ const { user: u, token } = JSON.parse(text);
if (!token) throw new Error("Login failed");
const expires = new Date();
@@ -490,7 +497,7 @@ export const ago = (t) => {
return `${days}d`;
};
-export const register = async (user, ip, cookies, loginRedirect) => {
+export const register = async (user, ip, cookies, loginRedirect, host?) => {
let error;
let sk;
@@ -501,7 +508,7 @@ export const register = async (user, ip, cookies, loginRedirect) => {
}
try {
- await login(user, cookies, ip);
+ await login(user, cookies, ip, host);
error = null;
} catch (e) {
const { message } = e as Error;