({ searchParams }: PageProps)
| 71 | } |
| 72 | |
| 73 | const Onboard = async ({ searchParams }: PageProps) => { |
| 74 | const resolvedSearchParams = searchParams ? await searchParams : {} |
| 75 | const authCode = resolvedSearchParams.auth_code |
| 76 | const referrerName = normalizeReferrer(resolvedSearchParams.referrer) |
| 77 | const session = await getServerSession(authOptions) |
| 78 | const user = session?.user |
| 79 | |
| 80 | if (!user) { |
| 81 | const params = new URLSearchParams() |
| 82 | if (authCode) params.set('auth_code', authCode) |
| 83 | if (referrerName) params.set('referrer', referrerName) |
| 84 | const query = params.toString() |
| 85 | const dest = authCode ? '/login' : '/get-started' |
| 86 | return redirect(query ? `${dest}?${query}` : dest) |
| 87 | } |
| 88 | |
| 89 | if (!authCode) { |
| 90 | return ( |
| 91 | <StatusCard |
| 92 | title={ |
| 93 | referrerName |
| 94 | ? `${referrerName} invited you to try Freebuff!` |
| 95 | : 'Welcome to Freebuff!' |
| 96 | } |
| 97 | description="" |
| 98 | message="You're all set! Head back to your terminal to continue." |
| 99 | /> |
| 100 | ) |
| 101 | } |
| 102 | |
| 103 | const authCodeResolution = await resolveCliAuthCode( |
| 104 | authCode, |
| 105 | consumeCliAuthCodeToken, |
| 106 | ) |
| 107 | |
| 108 | if (authCodeResolution.status === 'already_consumed') { |
| 109 | logger.info( |
| 110 | { |
| 111 | authCodeLength: authCode.length, |
| 112 | authCodeTrimmedLength: authCode.trim().length, |
| 113 | authCodeHashPrefix: getCliAuthCodeHashPrefix(authCode), |
| 114 | isOpaqueAuthCodeToken: isOpaqueCliAuthCodeToken(authCode), |
| 115 | userId: user.id, |
| 116 | }, |
| 117 | 'Reused Freebuff CLI auth code token', |
| 118 | ) |
| 119 | |
| 120 | return ( |
| 121 | <StatusCard |
| 122 | title="Login link already used" |
| 123 | description="This browser login link has already been used." |
| 124 | message="Return to your terminal to continue, or restart Freebuff if it is still waiting for login." |
| 125 | /> |
| 126 | ) |
| 127 | } |
| 128 | |
| 129 | if (authCodeResolution.status === 'missing') { |
| 130 | logger.info( |
nothing calls this directly
no test coverage detected