mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-02 18:18:43 +00:00
feat(ui): expose auth result with device code in hook
- add CopilotAuthResult interface with deviceCode field - expose startAuthAsync and authResult from useCopilot hook - immediately refetch status on auth success
This commit is contained in:
@@ -117,7 +117,14 @@ async function saveCopilotRawSettings(data: {
|
|||||||
return res.json();
|
return res.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function startCopilotAuth(): Promise<{ success: boolean; error?: string }> {
|
export interface CopilotAuthResult {
|
||||||
|
success: boolean;
|
||||||
|
error?: string;
|
||||||
|
deviceCode?: string;
|
||||||
|
verificationUrl?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function startCopilotAuth(): Promise<CopilotAuthResult> {
|
||||||
const res = await fetch(`${API_BASE}/copilot/auth/start`, { method: 'POST' });
|
const res = await fetch(`${API_BASE}/copilot/auth/start`, { method: 'POST' });
|
||||||
if (!res.ok) throw new Error('Failed to start auth');
|
if (!res.ok) throw new Error('Failed to start auth');
|
||||||
return res.json();
|
return res.json();
|
||||||
@@ -204,10 +211,8 @@ export function useCopilot() {
|
|||||||
const startAuthMutation = useMutation({
|
const startAuthMutation = useMutation({
|
||||||
mutationFn: startCopilotAuth,
|
mutationFn: startCopilotAuth,
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
// Delay refetch to allow auth to complete
|
// Auth completed - immediately refetch status
|
||||||
setTimeout(() => {
|
queryClient.invalidateQueries({ queryKey: ['copilot-status'] });
|
||||||
queryClient.invalidateQueries({ queryKey: ['copilot-status'] });
|
|
||||||
}, 2000);
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -264,7 +269,9 @@ export function useCopilot() {
|
|||||||
isSavingRawSettings: saveRawSettingsMutation.isPending,
|
isSavingRawSettings: saveRawSettingsMutation.isPending,
|
||||||
|
|
||||||
startAuth: startAuthMutation.mutate,
|
startAuth: startAuthMutation.mutate,
|
||||||
|
startAuthAsync: startAuthMutation.mutateAsync,
|
||||||
isAuthenticating: startAuthMutation.isPending,
|
isAuthenticating: startAuthMutation.isPending,
|
||||||
|
authResult: startAuthMutation.data,
|
||||||
|
|
||||||
startDaemon: startDaemonMutation.mutate,
|
startDaemon: startDaemonMutation.mutate,
|
||||||
isStartingDaemon: startDaemonMutation.isPending,
|
isStartingDaemon: startDaemonMutation.isPending,
|
||||||
|
|||||||
Reference in New Issue
Block a user