Added profile ARN handling in OAuth provider mapping and improved polling logic in OAuth modal for better user experience.
This commit is contained in:
parent
f4e08fcd16
commit
75f486b7a2
5 changed files with 105 additions and 17 deletions
|
|
@ -43,12 +43,14 @@ export default function KiroOAuthWrapper({ isOpen, providerInfo, onSuccess, onCl
|
|||
setAuthMethod(null);
|
||||
setSocialProvider(null);
|
||||
onSuccess?.();
|
||||
onClose?.(); // Close modal after success
|
||||
};
|
||||
|
||||
const handleDeviceSuccess = () => {
|
||||
setAuthMethod(null);
|
||||
setIdcConfig(null);
|
||||
onSuccess?.();
|
||||
onClose?.(); // Close modal after success
|
||||
};
|
||||
|
||||
// Show method selection first
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ export default function OAuthModal({ isOpen, provider, providerInfo, onSuccess,
|
|||
const [deviceData, setDeviceData] = useState(null);
|
||||
const [polling, setPolling] = useState(false);
|
||||
const popupRef = useRef(null);
|
||||
const pollingAbortRef = useRef(false);
|
||||
const { copied, copy } = useCopyToClipboard();
|
||||
|
||||
// State for client-only values to avoid hydration mismatch
|
||||
|
|
@ -66,12 +67,27 @@ export default function OAuthModal({ isOpen, provider, providerInfo, onSuccess,
|
|||
|
||||
// Poll for device code token
|
||||
const startPolling = useCallback(async (deviceCode, codeVerifier, interval, extraData) => {
|
||||
pollingAbortRef.current = false;
|
||||
setPolling(true);
|
||||
const maxAttempts = 60;
|
||||
|
||||
for (let i = 0; i < maxAttempts; i++) {
|
||||
// Check if polling should be aborted
|
||||
if (pollingAbortRef.current) {
|
||||
console.log("[OAuthModal] Polling aborted");
|
||||
setPolling(false);
|
||||
return;
|
||||
}
|
||||
|
||||
await new Promise((r) => setTimeout(r, interval * 1000));
|
||||
|
||||
// Check again after sleep
|
||||
if (pollingAbortRef.current) {
|
||||
console.log("[OAuthModal] Polling aborted after sleep");
|
||||
setPolling(false);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/oauth/${provider}/poll`, {
|
||||
method: "POST",
|
||||
|
|
@ -82,6 +98,7 @@ export default function OAuthModal({ isOpen, provider, providerInfo, onSuccess,
|
|||
const data = await res.json();
|
||||
|
||||
if (data.success) {
|
||||
pollingAbortRef.current = true; // Stop polling immediately
|
||||
setStep("success");
|
||||
setPolling(false);
|
||||
onSuccess?.();
|
||||
|
|
@ -182,7 +199,11 @@ export default function OAuthModal({ isOpen, provider, providerInfo, onSuccess,
|
|||
setIsDeviceCode(false);
|
||||
setDeviceData(null);
|
||||
setPolling(false);
|
||||
pollingAbortRef.current = false;
|
||||
startOAuthFlow();
|
||||
} else if (!isOpen) {
|
||||
// Abort polling when modal closes
|
||||
pollingAbortRef.current = true;
|
||||
}
|
||||
}, [isOpen, provider, startOAuthFlow]);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue