| "use client";
|
|
|
| import { useState, useCallback } from "react";
|
| import OAuthModal from "./OAuthModal";
|
| import KiroAuthModal from "./KiroAuthModal";
|
| import KiroSocialOAuthModal from "./KiroSocialOAuthModal";
|
|
|
| type KiroOAuthWrapperProps = {
|
| isOpen: boolean;
|
| providerInfo?: { id?: string; name?: string } | null;
|
| onSuccess?: () => void;
|
| onClose: () => void;
|
| reauthConnection?: null | { id?: string };
|
| };
|
|
|
| |
| |
| |
|
|
| export default function KiroOAuthWrapper({
|
| isOpen,
|
| providerInfo,
|
| onSuccess,
|
| onClose,
|
| reauthConnection,
|
| }: KiroOAuthWrapperProps) {
|
| const [authMethod, setAuthMethod] = useState(null);
|
| const [socialProvider, setSocialProvider] = useState(null);
|
| const [idcConfig, setIdcConfig] = useState(null);
|
|
|
| const handleMethodSelect = useCallback(
|
| (method, config) => {
|
| if (method === "builder-id") {
|
|
|
| setAuthMethod("builder-id");
|
| } else if (method === "idc") {
|
|
|
| setAuthMethod("idc");
|
| setIdcConfig(config);
|
| } else if (method === "social") {
|
|
|
| setAuthMethod("social");
|
| setSocialProvider(config.provider);
|
| } else if (method === "import") {
|
|
|
| onSuccess?.();
|
| }
|
| },
|
| [onSuccess]
|
| );
|
|
|
| const handleBack = () => {
|
| setAuthMethod(null);
|
| setSocialProvider(null);
|
| setIdcConfig(null);
|
| };
|
|
|
| const handleSocialSuccess = () => {
|
| setAuthMethod(null);
|
| setSocialProvider(null);
|
| onSuccess?.();
|
| };
|
|
|
| const handleDeviceSuccess = () => {
|
| setAuthMethod(null);
|
| setIdcConfig(null);
|
| onSuccess?.();
|
| };
|
|
|
|
|
| const oauthProviderId = providerInfo?.id || "kiro";
|
| const providerLabel = providerInfo?.name || "Kiro";
|
|
|
| if (!authMethod) {
|
| return (
|
| <KiroAuthModal
|
| isOpen={isOpen}
|
| providerId={oauthProviderId}
|
| providerLabel={providerLabel}
|
| onMethodSelect={handleMethodSelect}
|
| onClose={onClose}
|
| />
|
| );
|
| }
|
|
|
|
|
| if (authMethod === "builder-id" || authMethod === "idc") {
|
| return (
|
| <OAuthModal
|
| isOpen={isOpen}
|
| provider={oauthProviderId}
|
| providerInfo={providerInfo}
|
| onSuccess={handleDeviceSuccess}
|
| reauthConnection={reauthConnection}
|
| onClose={handleBack}
|
| idcConfig={idcConfig}
|
| />
|
| );
|
| }
|
|
|
|
|
| if (authMethod === "social" && socialProvider) {
|
| return (
|
| <KiroSocialOAuthModal
|
| isOpen={isOpen}
|
| provider={socialProvider}
|
| targetProvider={oauthProviderId}
|
| providerLabel={providerLabel}
|
| onSuccess={handleSocialSuccess}
|
| onClose={handleBack}
|
| />
|
| );
|
| }
|
|
|
| return null;
|
| }
|
|
|