Stabilize mobile auth session handling

This commit is contained in:
2026-06-29 17:58:50 -04:00
parent 477459edd4
commit 57e1aa658a
25 changed files with 1126 additions and 192 deletions
+4 -10
View File
@@ -1,11 +1,5 @@
import { getApiUrl } from "@/lib/config";
type ApiError = { error?: string; message?: string };
async function parseError(res: Response) {
const data = (await res.json().catch(() => ({}))) as ApiError;
return data.error ?? data.message ?? "Something went wrong";
}
import { readHttpErrorMessage } from "@/lib/trpc-errors";
export async function registerAccount(input: {
firstName: string;
@@ -20,7 +14,7 @@ export async function registerAccount(input: {
});
if (!res.ok) {
throw new Error(await parseError(res));
throw new Error(await readHttpErrorMessage(res));
}
}
@@ -32,7 +26,7 @@ export async function requestPasswordReset(email: string) {
});
if (!res.ok) {
throw new Error(await parseError(res));
throw new Error(await readHttpErrorMessage(res));
}
const data = (await res.json()) as { message?: string };
@@ -47,6 +41,6 @@ export async function resetPassword(token: string, password: string) {
});
if (!res.ok) {
throw new Error(await parseError(res));
throw new Error(await readHttpErrorMessage(res));
}
}