({ searchParams }: PageProps)
| 30 | } |
| 31 | |
| 32 | const Onboard = async ({ searchParams }: PageProps) => { |
| 33 | const resolvedSearchParams = searchParams ? await searchParams : {} |
| 34 | const authCode = resolvedSearchParams.auth_code |
| 35 | const session = await getServerSession(authOptions) |
| 36 | const user = session?.user |
| 37 | |
| 38 | if (!user) { |
| 39 | const params = new URLSearchParams() |
| 40 | if (authCode) params.set('auth_code', authCode) |
| 41 | const query = params.toString() |
| 42 | return redirect( |
| 43 | query ? `/login?${query}` : env.NEXT_PUBLIC_CODEBUFF_APP_URL, |
| 44 | ) |
| 45 | } |
| 46 | |
| 47 | if (!authCode) { |
| 48 | return ( |
| 49 | <WelcomeCard |
| 50 | fallbackTitle="Welcome to Codebuff!" |
| 51 | description="" |
| 52 | message="You're all set! Head back to your terminal to continue." |
| 53 | /> |
| 54 | ) |
| 55 | } |
| 56 | |
| 57 | const authCodeResolution = await resolveCliAuthCode( |
| 58 | authCode, |
| 59 | consumeCliAuthCodeToken, |
| 60 | ) |
| 61 | |
| 62 | if (authCodeResolution.status === 'already_consumed') { |
| 63 | return ( |
| 64 | <CardWithBeams |
| 65 | title="This login link was already used" |
| 66 | description="Return to your terminal to continue, or restart Codebuff if it is still waiting for login." |
| 67 | content={<p>You can close this browser window.</p>} |
| 68 | /> |
| 69 | ) |
| 70 | } |
| 71 | |
| 72 | if (authCodeResolution.status === 'missing') { |
| 73 | return ( |
| 74 | <CardWithBeams |
| 75 | title="This login link has expired" |
| 76 | description="Return to your terminal and restart Codebuff to generate a new login link." |
| 77 | content={<p>You can close this browser window.</p>} |
| 78 | /> |
| 79 | ) |
| 80 | } |
| 81 | |
| 82 | const { authCode: resolvedAuthCode } = authCodeResolution |
| 83 | const { fingerprintId, expiresAt, receivedHash } = |
| 84 | parseAuthCode(resolvedAuthCode) |
| 85 | const { valid, expectedHash: fingerprintHash } = validateAuthCode( |
| 86 | receivedHash, |
| 87 | fingerprintId, |
| 88 | expiresAt, |
| 89 | env.NEXTAUTH_SECRET, |
nothing calls this directly
no test coverage detected