Skip to content

Commit 6b85906

Browse files
committed
Expand Freebuff auth code diagnostics
1 parent be127dd commit 6b85906

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

freebuff/web/src/app/api/auth/[...nextauth]/auth-options.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ import GitHubProvider from 'next-auth/providers/github'
1515
import type { NextAuthOptions } from 'next-auth'
1616
import type { Adapter } from 'next-auth/adapters'
1717

18+
import {
19+
getCliAuthCodeHashPrefix,
20+
isCliAuthCodeCandidate,
21+
} from '@/app/onboard/_helpers'
1822
import { logger } from '@/util/logger'
1923

2024
async function createAndLinkStripeCustomer(params: {
@@ -104,6 +108,31 @@ export const authOptions: NextAuthOptions = {
104108
const authCode = potentialRedirectUrl.searchParams.get('auth_code')
105109

106110
if (authCode) {
111+
if (!isCliAuthCodeCandidate(authCode)) {
112+
const searchParamKeys = Array.from(
113+
potentialRedirectUrl.searchParams.keys(),
114+
).sort()
115+
logger.warn(
116+
{
117+
authCodeLength: authCode.length,
118+
authCodeTrimmedLength: authCode.trim().length,
119+
authCodeHashPrefix: getCliAuthCodeHashPrefix(authCode),
120+
authCodeParamCount:
121+
potentialRedirectUrl.searchParams.getAll('auth_code').length,
122+
searchParamKeys,
123+
searchParamCount: searchParamKeys.length,
124+
hasCallbackUrlParam: searchParamKeys.includes('callbackUrl'),
125+
hasCodeParam: searchParamKeys.includes('code'),
126+
hasRedirectParam: searchParamKeys.includes('redirect'),
127+
dotCount: authCode.match(/\./g)?.length ?? 0,
128+
hyphenCount: authCode.match(/-/g)?.length ?? 0,
129+
redirectUrlOrigin: potentialRedirectUrl.origin,
130+
baseUrl,
131+
},
132+
'Freebuff auth redirect received non-CLI-shaped auth_code',
133+
)
134+
}
135+
107136
const onboardUrl = new URL(`${baseUrl}/onboard`)
108137
potentialRedirectUrl.searchParams.forEach((value, key) => {
109138
onboardUrl.searchParams.set(key, value)

freebuff/web/src/app/login/page.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export default async function LoginPage({
2929
const resolvedSearchParams = searchParams ? await searchParams : {}
3030
const rawAuthCode = resolvedSearchParams?.auth_code
3131
const authCode = Array.isArray(rawAuthCode) ? rawAuthCode[0] : rawAuthCode
32+
const searchParamKeys = Object.keys(resolvedSearchParams).sort()
3233

3334
if (authCode) {
3435
if (!isCliAuthCodeCandidate(authCode)) {
@@ -41,6 +42,11 @@ export default async function LoginPage({
4142
authCodeParamCount: Array.isArray(rawAuthCode)
4243
? rawAuthCode.length
4344
: 1,
45+
searchParamKeys,
46+
searchParamCount: searchParamKeys.length,
47+
hasCallbackUrlParam: searchParamKeys.includes('callbackUrl'),
48+
hasCodeParam: searchParamKeys.includes('code'),
49+
hasRedirectParam: searchParamKeys.includes('redirect'),
4450
dotCount: authCode.match(/\./g)?.length ?? 0,
4551
hyphenCount: authCode.match(/-/g)?.length ?? 0,
4652
requestHost: headerStore.get('host') ?? '',

0 commit comments

Comments
 (0)