diff --git a/packages/app/src/components/dialog-connect-provider.tsx b/packages/app/src/components/dialog-connect-provider.tsx index 0fb89d29f921..3a57769b5a68 100644 --- a/packages/app/src/components/dialog-connect-provider.tsx +++ b/packages/app/src/components/dialog-connect-provider.tsx @@ -65,6 +65,7 @@ export function DialogConnectProvider(props: { provider: string; directory?: Acc const [store, setStore] = createStore({ methodIndex: undefined as undefined | number, authorization: undefined as undefined | ProviderAuthAuthorization, + promptInputs: undefined as undefined | Record, state: "pending" as undefined | "pending" | "complete" | "error" | "prompt", error: undefined as string | undefined, }) @@ -73,6 +74,7 @@ export function DialogConnectProvider(props: { provider: string; directory?: Acc | { type: "method.select"; index: number } | { type: "method.reset" } | { type: "auth.prompt" } + | { type: "auth.inputs"; inputs: Record } | { type: "auth.pending" } | { type: "auth.complete"; authorization: ProviderAuthAuthorization } | { type: "auth.error"; error: string } @@ -83,6 +85,7 @@ export function DialogConnectProvider(props: { provider: string; directory?: Acc if (action.type === "method.select") { draft.methodIndex = action.index draft.authorization = undefined + draft.promptInputs = undefined draft.state = undefined draft.error = undefined return @@ -90,6 +93,7 @@ export function DialogConnectProvider(props: { provider: string; directory?: Acc if (action.type === "method.reset") { draft.methodIndex = undefined draft.authorization = undefined + draft.promptInputs = undefined draft.state = undefined draft.error = undefined return @@ -99,6 +103,12 @@ export function DialogConnectProvider(props: { provider: string; directory?: Acc draft.error = undefined return } + if (action.type === "auth.inputs") { + draft.promptInputs = action.inputs + draft.state = undefined + draft.error = undefined + return + } if (action.type === "auth.pending") { draft.state = "pending" draft.error = undefined @@ -151,6 +161,15 @@ export function DialogConnectProvider(props: { provider: string; directory?: Acc const method = methods()[index] dispatch({ type: "method.select", index }) + if (method.type === "api" && method.prompts?.length) { + if (!inputs) { + dispatch({ type: "auth.prompt" }) + return + } + dispatch({ type: "auth.inputs", inputs }) + return + } + if (method.type === "oauth") { if (method.prompts?.length && !inputs) { dispatch({ type: "auth.prompt" }) @@ -190,7 +209,7 @@ export function DialogConnectProvider(props: { provider: string; directory?: Acc } } - function OAuthPromptsView() { + function AuthPromptsView() { const [formStore, setFormStore] = createStore({ value: {} as Record, index: 0, @@ -198,8 +217,7 @@ export function DialogConnectProvider(props: { provider: string; directory?: Acc const prompts = createMemo>(() => { const value = method() - if (value?.type !== "oauth") return [] - return value.prompts ?? [] + return value?.prompts ?? [] }) const matches = (prompt: NonNullable[number]>, value: Record) => { if (!prompt.when) return true @@ -230,6 +248,10 @@ export function DialogConnectProvider(props: { provider: string; directory?: Acc setFormStore("index", next) return } + if (method()?.type === "api") { + dispatch({ type: "auth.inputs", inputs: value }) + return + } await selectMethod(store.methodIndex, value) } @@ -414,6 +436,7 @@ export function DialogConnectProvider(props: { provider: string; directory?: Acc auth: { type: "api", key: apiKey, + ...(store.promptInputs ? { metadata: store.promptInputs } : {}), }, }) await complete() @@ -622,7 +645,7 @@ export function DialogConnectProvider(props: { provider: string; directory?: Acc - +