Skip to content

Commit f4c816b

Browse files
OpeOginnigithub-actions[bot]
authored andcommitted
fix(desktop): recognize normal auth metadata input prompts in connect provider dialog (anomalyco#33024)
1 parent c7a83ab commit f4c816b

1 file changed

Lines changed: 27 additions & 4 deletions

File tree

packages/app/src/components/dialog-connect-provider.tsx

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export function DialogConnectProvider(props: { provider: string; directory?: Acc
6565
const [store, setStore] = createStore({
6666
methodIndex: undefined as undefined | number,
6767
authorization: undefined as undefined | ProviderAuthAuthorization,
68+
promptInputs: undefined as undefined | Record<string, string>,
6869
state: "pending" as undefined | "pending" | "complete" | "error" | "prompt",
6970
error: undefined as string | undefined,
7071
})
@@ -73,6 +74,7 @@ export function DialogConnectProvider(props: { provider: string; directory?: Acc
7374
| { type: "method.select"; index: number }
7475
| { type: "method.reset" }
7576
| { type: "auth.prompt" }
77+
| { type: "auth.inputs"; inputs: Record<string, string> }
7678
| { type: "auth.pending" }
7779
| { type: "auth.complete"; authorization: ProviderAuthAuthorization }
7880
| { type: "auth.error"; error: string }
@@ -83,13 +85,15 @@ export function DialogConnectProvider(props: { provider: string; directory?: Acc
8385
if (action.type === "method.select") {
8486
draft.methodIndex = action.index
8587
draft.authorization = undefined
88+
draft.promptInputs = undefined
8689
draft.state = undefined
8790
draft.error = undefined
8891
return
8992
}
9093
if (action.type === "method.reset") {
9194
draft.methodIndex = undefined
9295
draft.authorization = undefined
96+
draft.promptInputs = undefined
9397
draft.state = undefined
9498
draft.error = undefined
9599
return
@@ -99,6 +103,12 @@ export function DialogConnectProvider(props: { provider: string; directory?: Acc
99103
draft.error = undefined
100104
return
101105
}
106+
if (action.type === "auth.inputs") {
107+
draft.promptInputs = action.inputs
108+
draft.state = undefined
109+
draft.error = undefined
110+
return
111+
}
102112
if (action.type === "auth.pending") {
103113
draft.state = "pending"
104114
draft.error = undefined
@@ -151,6 +161,15 @@ export function DialogConnectProvider(props: { provider: string; directory?: Acc
151161
const method = methods()[index]
152162
dispatch({ type: "method.select", index })
153163

164+
if (method.type === "api" && method.prompts?.length) {
165+
if (!inputs) {
166+
dispatch({ type: "auth.prompt" })
167+
return
168+
}
169+
dispatch({ type: "auth.inputs", inputs })
170+
return
171+
}
172+
154173
if (method.type === "oauth") {
155174
if (method.prompts?.length && !inputs) {
156175
dispatch({ type: "auth.prompt" })
@@ -190,16 +209,15 @@ export function DialogConnectProvider(props: { provider: string; directory?: Acc
190209
}
191210
}
192211

193-
function OAuthPromptsView() {
212+
function AuthPromptsView() {
194213
const [formStore, setFormStore] = createStore({
195214
value: {} as Record<string, string>,
196215
index: 0,
197216
})
198217

199218
const prompts = createMemo<NonNullable<ProviderAuthMethod["prompts"]>>(() => {
200219
const value = method()
201-
if (value?.type !== "oauth") return []
202-
return value.prompts ?? []
220+
return value?.prompts ?? []
203221
})
204222
const matches = (prompt: NonNullable<ReturnType<typeof prompts>[number]>, value: Record<string, string>) => {
205223
if (!prompt.when) return true
@@ -230,6 +248,10 @@ export function DialogConnectProvider(props: { provider: string; directory?: Acc
230248
setFormStore("index", next)
231249
return
232250
}
251+
if (method()?.type === "api") {
252+
dispatch({ type: "auth.inputs", inputs: value })
253+
return
254+
}
233255
await selectMethod(store.methodIndex, value)
234256
}
235257

@@ -414,6 +436,7 @@ export function DialogConnectProvider(props: { provider: string; directory?: Acc
414436
auth: {
415437
type: "api",
416438
key: apiKey,
439+
...(store.promptInputs ? { metadata: store.promptInputs } : {}),
417440
},
418441
})
419442
await complete()
@@ -622,7 +645,7 @@ export function DialogConnectProvider(props: { provider: string; directory?: Acc
622645
</div>
623646
</Match>
624647
<Match when={store.state === "prompt"}>
625-
<OAuthPromptsView />
648+
<AuthPromptsView />
626649
</Match>
627650
<Match when={store.state === "error"}>
628651
<div class="text-14-regular text-text-base">

0 commit comments

Comments
 (0)