feat(#417): update auth-client.ts error messages to PDA-friendly

Uses parseAuthError from auth-errors module for consistent
PDA-friendly error messages in signInWithCredentials.

Refs #417
This commit is contained in:
Jason Woltje
2026-02-16 12:15:25 -06:00
parent 07084208a7
commit f1ee0df933
2 changed files with 224 additions and 2 deletions

View File

@@ -9,6 +9,7 @@
import { createAuthClient } from "better-auth/react";
import { genericOAuthClient } from "better-auth/client/plugins";
import { API_BASE_URL } from "./config";
import { parseAuthError } from "./auth/auth-errors";
/**
* Auth client instance configured for Mosaic Stack.
@@ -42,8 +43,9 @@ export async function signInWithCredentials(username: string, password: string):
});
if (!response.ok) {
const error = (await response.json().catch(() => ({}))) as { message?: string };
throw new Error(error.message ?? "Authentication failed");
const errorBody = (await response.json().catch(() => ({}))) as { message?: string };
const parsed = parseAuthError(errorBody.message ? new Error(errorBody.message) : response);
throw new Error(parsed.message);
}
const data = (await response.json()) as unknown;