| 312 | authorization: ProviderAuthAuthorization |
| 313 | } |
| 314 | function CodeMethod(props: CodeMethodProps) { |
| 315 | const { theme } = useTheme() |
| 316 | const sdk = useSDK() |
| 317 | const sync = useSync() |
| 318 | const dialog = useDialog() |
| 319 | const [error, setError] = createSignal(false) |
| 320 | |
| 321 | return ( |
| 322 | <DialogPrompt |
| 323 | title={props.title} |
| 324 | placeholder="Authorization code" |
| 325 | onConfirm={async (value) => { |
| 326 | const { error } = await sdk.client.provider.oauth.callback({ |
| 327 | providerID: props.providerID, |
| 328 | method: props.index, |
| 329 | code: value, |
| 330 | }) |
| 331 | if (!error) { |
| 332 | await sdk.client.instance.dispose() |
| 333 | await sync.bootstrap() |
| 334 | dialog.replace(() => <DialogModel providerID={props.providerID} />) |
| 335 | return |
| 336 | } |
| 337 | setError(true) |
| 338 | }} |
| 339 | description={() => ( |
| 340 | <box gap={1}> |
| 341 | <text fg={theme.textMuted}>{props.authorization.instructions}</text> |
| 342 | <Link href={props.authorization.url} fg={theme.primary} /> |
| 343 | <Show when={error()}> |
| 344 | <text fg={theme.error}>Invalid code</text> |
| 345 | </Show> |
| 346 | </box> |
| 347 | )} |
| 348 | /> |
| 349 | ) |
| 350 | } |
| 351 | |
| 352 | interface ApiMethodProps { |
| 353 | providerID: string |