Files
slp-modular-cms/frontend/src/api/useSetup.ts
T
SluijsensandClaude Haiku 4.5 8d95754ece fix(unit-2-auth): Fix API endpoint paths and JSON casing for real backend
- Add /api/v1/ prefix to all Unit 2 API calls (Setup/status, Setup/owner,
  Invitation/validate, Invitation/complete) to match backend ApiPrefixConvention
- Fix setup status endpoint to POST /api/v1/Setup/owner (not /Setup)
- Handle PascalCase 'Initialized' response from .NET backend without camelCase policy
- Update all MSW mock handlers to match corrected /api/v1/ URL patterns
- Remove unused imports from RouteGuard.test.tsx

Root cause: backend uses ApiPrefixConvention('api/v1') but frontend calls
were missing the prefix, and .NET defaults to PascalCase JSON serialization.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-06-22 10:55:34 +02:00

46 lines
1.1 KiB
TypeScript

import { useState, useCallback } from 'react';
import { api } from '../lib/api-client';
interface SetupRequest {
name: string;
email: string;
password: string;
language: 'en' | 'nl';
}
interface SetupResponse {
message: string;
user: {
id: string;
name: string;
email: string;
role: string;
};
}
export function useSetup() {
const [isPending, setIsPending] = useState(false);
const [error, setError] = useState<Error | null>(null);
const mutateAsync = useCallback(async (data: SetupRequest): Promise<SetupResponse> => {
setIsPending(true);
setError(null);
try {
const response = await api.post('/api/v1/Setup/owner', data);
return response as SetupResponse;
} catch (err) {
const error = err instanceof Error ? err : new Error(String(err));
setError(error);
throw error;
} finally {
setIsPending(false);
}
}, []);
return {
mutateAsync,
isPending,
error
};
}