feat(auth): add remembered local login to the frontend

This commit is contained in:
2026-08-17 04:52:39 +02:00
parent 8c67cb75dc
commit 202822f3ba
36 changed files with 2649 additions and 163 deletions
+5 -13
View File
@@ -1,4 +1,4 @@
import { ApiError, apiFetch } from "./client";
import { ApiError, apiErrorMessage, apiFetch } from "./client";
export type PiReasoning = "low" | "medium" | "high";
@@ -54,22 +54,14 @@ const errorCodes = new Set<PiManagementApiErrorCode>([
"pi_management_write_failed",
]);
function object(value: unknown): Record<string, unknown> | undefined {
return value && typeof value === "object" && !Array.isArray(value)
? value as Record<string, unknown>
: undefined;
}
/** Narrows the sanctioned error payload without ever surfacing its raw response body. */
/** Narrows the sanctioned error code and derives its message locally. */
export function asPiManagementApiError(error: unknown): PiManagementApiError | undefined {
if (!(error instanceof ApiError)) return undefined;
const payload = object(error.payload);
const code = payload?.code;
const message = payload?.error;
if (typeof code !== "string" || !errorCodes.has(code as PiManagementApiErrorCode) || typeof message !== "string") {
const code = error.code;
if (typeof code !== "string" || !errorCodes.has(code as PiManagementApiErrorCode)) {
return undefined;
}
return { status: error.status, code: code as PiManagementApiErrorCode, message };
return { status: error.status, code: code as PiManagementApiErrorCode, message: apiErrorMessage(error) };
}
export const getPiManagementStatus = () => apiFetch<PiManagementStatus>("/pi-management/status");