fix(webui): complete Copilot device sign-in in the browser
Reuse the device-flow adapter from #5498, expose its prompt in the existing OAuth dialog, and keep credential persistence scoped to uncancelled completion. Co-authored-by: chengyongru <chengyongru.ai@gmail.com>
This commit is contained in:
1 parent
aca59431fe
commit
a44f28e656
24 files changed
+563
-39
No files matched your search
@@ -3,7 +3,7 @@ import { useEffect, type Dispatch, type SetStateAction } from "react";
|
||||
import type { ApplySettingsPayload } from "@/components/settings/contracts";
|
||||
import { providerFormFromRow } from "@/components/settings/models/ProviderSettings";
|
||||
import type { ModelSettingsState } from "@/components/settings/models/useModelSettingsState";
|
||||
import { completeProviderOAuth } from "@/lib/api";
|
||||
import { cancelProviderOAuth, completeProviderOAuth } from "@/lib/api";
|
||||
import type { NanobotClient } from "@/lib/nanobot-client";
|
||||
import type {
|
||||
ProviderOAuthCompletionResult,
|
||||
@@ -22,7 +22,7 @@ interface ProviderOAuthPollingOptions {
|
||||
client: NanobotClient;
|
||||
applyPayload: ApplySettingsPayload;
|
||||
setError: Dispatch<SetStateAction<string | null>>;
|
||||
closeProviderOAuthFlow: () => void;
|
||||
closeProviderOAuthFlow: (cancelPending?: boolean) => void;
|
||||
}
|
||||
|
||||
export function useProviderOAuthPolling({
|
||||
@@ -58,7 +58,7 @@ export function useProviderOAuthPolling({
|
||||
}
|
||||
applyPayload(payload, { preserveAgentForm: true });
|
||||
setError(null);
|
||||
closeProviderOAuthFlow();
|
||||
closeProviderOAuthFlow(false);
|
||||
} catch (err) {
|
||||
if (
|
||||
cancelled
|
||||
@@ -72,6 +72,12 @@ export function useProviderOAuthPolling({
|
||||
return () => {
|
||||
cancelled = true;
|
||||
if (timer !== null) window.clearTimeout(timer);
|
||||
if (providerOAuthFlow.completion_input === "device_code"
|
||||
&& providerOAuthFlowRef.current?.flow_id === providerOAuthFlow.flow_id) {
|
||||
providerOAuthFlowRef.current = null;
|
||||
void cancelProviderOAuth(client, providerOAuthFlow.provider, providerOAuthFlow.flow_id)
|
||||
.catch(() => {});
|
||||
}
|
||||
};
|
||||
}, [applyPayload, client, closeProviderOAuthFlow, providerOAuthFlow]);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user