Fix auth modal feedback and production deploy config
Some checks failed
Build & Push Docker Image to Gitea Registry / build-and-push (push) Failing after 6s

This commit is contained in:
Kroonk
2026-05-20 17:25:15 +02:00
parent 6f96b26e4c
commit 5e996f791e
4 changed files with 77 additions and 66 deletions

View File

@@ -1,6 +1,19 @@
import { API_URL } from "@/config";
import type { User } from "@michess/types";
const readErrorMessage = async (res: Response, fallback: string) => {
try {
const body = await res.json();
if (typeof body?.message === "string") {
return body.message;
}
} catch (err) {
// Response did not include a JSON error body.
}
return fallback;
};
export const fetchSession = async () => {
try {
const res = await fetch(`${API_URL}/v1/auth`, {
@@ -30,8 +43,10 @@ export const setGuestSession = async (name: string) => {
const user: User = await res.json();
return user;
}
return await readErrorMessage(res, "Could not start guest session.");
} catch (err) {
console.error(err);
return "Could not reach the server. Please try again.";
}
};
@@ -48,12 +63,11 @@ export const register = async (name: string, password: string, email?: string) =
if (res.status === 201) {
const user: User = await res.json();
return user;
} else if (res.status === 409) {
const { message } = await res.json();
return message as string;
}
return await readErrorMessage(res, "Registration failed. Please try again.");
} catch (err) {
console.error(err);
return "Could not reach the server. Please try again.";
}
};
@@ -70,12 +84,11 @@ export const login = async (name: string, password: string) => {
if (res.status === 200) {
const user: User = await res.json();
return user;
} else if (res.status === 404 || res.status === 401) {
const { message } = await res.json();
return message as string;
}
return await readErrorMessage(res, "Login failed. Please try again.");
} catch (err) {
console.error(err);
return "Could not reach the server. Please try again.";
}
};
@@ -107,11 +120,10 @@ export const updateUser = async (name?: string, email?: string, password?: strin
if (res.status === 200) {
const user: User = await res.json();
return user;
} else if (res.status === 409) {
const { message } = await res.json();
return message as string;
}
return await readErrorMessage(res, "Could not update settings. Please try again.");
} catch (err) {
console.error(err);
return "Could not reach the server. Please try again.";
}
};