04319025de
Under AUTH_ENABLED=true, api/services.ts, api/widgets.ts, and api/backups.ts called fetch() directly without attaching the OIDC access token, so every services/widgets/backups request 401'd while api/client.ts requests succeeded. The token was only attached in client.ts. Extract the auth-attaching fetch helpers (buildUrl/buildHeaders/ readErrorDetail + get/post/put/del/postForm) into a new api/shared.ts that consults getAccessToken(), rewrite services.ts/widgets.ts/ backups.ts to use them, and consolidate client.ts to import from shared.ts (removing its duplicated copies). Now every backend request goes through one auth-attaching path. As a side benefit, error messages surface the HTTP status + backend detail instead of a generic "Failed to ..." string. Bug masked in dev because dev runs AUTH_ENABLED=false. npm run build clean; 0 lint errors; 72 frontend tests pass.
43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import { del, get, post, put } from "./shared";
|
|
import type {
|
|
BuiltinWidgetKindInfo,
|
|
WidgetDataResponse,
|
|
WidgetInstance,
|
|
WidgetInstanceInput,
|
|
} from "../types";
|
|
|
|
export async function fetchBuiltinWidgetKinds(): Promise<
|
|
BuiltinWidgetKindInfo[]
|
|
> {
|
|
return get<BuiltinWidgetKindInfo[]>("/api/widgets/builtin");
|
|
}
|
|
|
|
export async function fetchWidgetInstances(): Promise<WidgetInstance[]> {
|
|
return get<WidgetInstance[]>("/api/widgets/instances");
|
|
}
|
|
|
|
export async function createWidgetInstance(
|
|
input: WidgetInstanceInput,
|
|
): Promise<WidgetInstance> {
|
|
return post<WidgetInstance>("/api/widgets/instances", input);
|
|
}
|
|
|
|
export async function updateWidgetInstance(
|
|
input: WidgetInstanceInput,
|
|
): Promise<WidgetInstance> {
|
|
if (!input.id) throw new Error("Widget ID is required for update");
|
|
return put<WidgetInstance>(`/api/widgets/instances/${input.id}`, input);
|
|
}
|
|
|
|
export async function deleteWidgetInstance(
|
|
widgetId: string,
|
|
): Promise<{ status: string }> {
|
|
return del<{ status: string }>(`/api/widgets/instances/${widgetId}`);
|
|
}
|
|
|
|
export async function fetchWidgetData(
|
|
widgetId: string,
|
|
): Promise<WidgetDataResponse> {
|
|
return get<WidgetDataResponse>(`/api/widgets/instances/${widgetId}/data`);
|
|
}
|