(ctx: OAuthReturnContext)
| 17 | const CONTEXT_MAX_AGE_MS = 15 * 60 * 1000 |
| 18 | |
| 19 | async function resolveOAuthMessage(ctx: OAuthReturnContext): Promise<string> { |
| 20 | if (ctx.reconnect) { |
| 21 | return `"${ctx.displayName}" reconnected successfully.` |
| 22 | } |
| 23 | |
| 24 | try { |
| 25 | const data = await requestJson(listWorkspaceCredentialsContract, { |
| 26 | query: { workspaceId: ctx.workspaceId, type: 'oauth' }, |
| 27 | }) |
| 28 | const oauthCredentials = data.credentials ?? [] |
| 29 | |
| 30 | const forProvider = oauthCredentials.filter((c) => c.providerId === ctx.providerId) |
| 31 | if (forProvider.length > ctx.preCount) { |
| 32 | return `"${ctx.displayName}" credential connected successfully.` |
| 33 | } |
| 34 | |
| 35 | const existing = forProvider[0] |
| 36 | return `This account is already connected as "${existing?.displayName || ctx.displayName}".` |
| 37 | } catch { |
| 38 | return `"${ctx.displayName}" credential connected successfully.` |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | function dispatchCredentialUpdate(ctx: OAuthReturnContext) { |
| 43 | window.dispatchEvent( |
no test coverage detected