Stabilize mobile auth session handling
This commit is contained in:
+4
-10
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user