|
1 | 1 | import { ChipLink } from '@sim/emcn' |
| 2 | +import { isValidUuid } from '@sim/utils/id' |
2 | 3 | import type { Metadata } from 'next' |
| 4 | +import { |
| 5 | + CREDENTIAL_GROUP_OAUTH_FAILURE_MESSAGES, |
| 6 | + isCredentialGroupOAuthFailure, |
| 7 | +} from '@/lib/credential-groups/oauth-completion' |
3 | 8 | import { APP_ENTRY_PATH } from '@/lib/navigation/paths' |
4 | 9 | import { AuthHeader, AuthShell } from '@/app/(auth)/components' |
| 10 | +import { CredentialGroupCompletionHandoff } from '@/app/credential-groups/complete/completion-handoff' |
5 | 11 |
|
6 | 12 | export const metadata: Metadata = { |
7 | 13 | title: 'Accounts connected', |
8 | 14 | robots: { index: false, follow: false }, |
9 | 15 | } |
10 | 16 |
|
11 | | -const OAUTH_FAILURE_MESSAGES = { |
12 | | - expired: 'This connection attempt expired. Open Sim and start connecting your account again.', |
13 | | - denied: 'Authorization was canceled. Open Sim to try again.', |
14 | | - account_mismatch: 'Choose the account matching your Sim email address.', |
15 | | - permissions_required: 'All requested permissions are required to connect this account.', |
16 | | - configuration_changed: 'The connection settings changed. Open Sim to try again.', |
17 | | - rate_limited: 'Too many authorization attempts. Wait a few minutes and try again.', |
18 | | - unavailable: 'This connection is unavailable. Open Sim to try again.', |
19 | | - failed: 'Account authorization did not complete. Open Sim to try again.', |
20 | | -} as const |
21 | | - |
22 | 17 | export default async function CredentialGroupCompletePage({ |
23 | 18 | searchParams, |
24 | 19 | }: { |
25 | | - searchParams: Promise<{ oauth?: string | string[] }> |
| 20 | + searchParams: Promise<{ oauth?: string | string[]; completionId?: string | string[] }> |
26 | 21 | }) { |
27 | | - const { oauth } = await searchParams |
28 | | - const error = |
29 | | - typeof oauth === 'string' && Object.hasOwn(OAUTH_FAILURE_MESSAGES, oauth) |
30 | | - ? OAUTH_FAILURE_MESSAGES[oauth as keyof typeof OAUTH_FAILURE_MESSAGES] |
31 | | - : undefined |
| 22 | + const { oauth, completionId } = await searchParams |
| 23 | + const failure = |
| 24 | + oauth === undefined ? undefined : isCredentialGroupOAuthFailure(oauth) ? oauth : 'failed' |
| 25 | + const error = failure ? CREDENTIAL_GROUP_OAUTH_FAILURE_MESSAGES[failure] : undefined |
32 | 26 | return ( |
33 | 27 | <AuthShell> |
| 28 | + {typeof completionId === 'string' && isValidUuid(completionId) && ( |
| 29 | + <CredentialGroupCompletionHandoff completionId={completionId} failure={failure} /> |
| 30 | + )} |
34 | 31 | <AuthHeader |
35 | 32 | title={error ? 'Account not connected' : 'Accounts connected'} |
36 | 33 | description={error ?? 'Your accounts are ready to use — you can close this tab.'} |
|
0 commit comments