11'use server'
22
33import { env } from '@codebuff/common/env'
4+ import { headers } from 'next/headers'
45
6+ import {
7+ getCliAuthCodeHashPrefix ,
8+ isAuthCodeExpired ,
9+ isCliAuthCodeCandidate ,
10+ parseAuthCode ,
11+ } from '@/app/onboard/_helpers'
512import { BackgroundBeams } from '@/components/background-beams'
613import { HeroGrid } from '@/components/hero-grid'
714import { LoginCard } from '@/components/login/login-card'
@@ -12,17 +19,61 @@ import {
1219 CardDescription ,
1320 CardContent ,
1421} from '@/components/ui/card'
15- import { isAuthCodeExpired , parseAuthCode } from '@/app/onboard/_helpers '
22+ import { logger } from '@/util/logger '
1623
1724export default async function LoginPage ( {
1825 searchParams,
1926} : {
2027 searchParams ?: Promise < { [ key : string ] : string | string [ ] | undefined } >
2128} ) {
2229 const resolvedSearchParams = searchParams ? await searchParams : { }
23- const authCode = resolvedSearchParams ?. auth_code as string | undefined
30+ const rawAuthCode = resolvedSearchParams ?. auth_code
31+ const authCode = Array . isArray ( rawAuthCode ) ? rawAuthCode [ 0 ] : rawAuthCode
2432
2533 if ( authCode ) {
34+ if ( ! isCliAuthCodeCandidate ( authCode ) ) {
35+ const headerStore = await headers ( )
36+ logger . warn (
37+ {
38+ authCodeLength : authCode . length ,
39+ authCodeTrimmedLength : authCode . trim ( ) . length ,
40+ authCodeHashPrefix : getCliAuthCodeHashPrefix ( authCode ) ,
41+ authCodeParamCount : Array . isArray ( rawAuthCode )
42+ ? rawAuthCode . length
43+ : 1 ,
44+ dotCount : authCode . match ( / \. / g) ?. length ?? 0 ,
45+ hyphenCount : authCode . match ( / - / g) ?. length ?? 0 ,
46+ requestHost : headerStore . get ( 'host' ) ?? '' ,
47+ forwardedHost : headerStore . get ( 'x-forwarded-host' ) ?? '' ,
48+ forwardedProto : headerStore . get ( 'x-forwarded-proto' ) ?? '' ,
49+ originHeader : headerStore . get ( 'origin' ) ?? '' ,
50+ referer : headerStore . get ( 'referer' ) ?? '' ,
51+ userAgent : headerStore . get ( 'user-agent' ) ?? '' ,
52+ referrerParam :
53+ typeof resolvedSearchParams . referrer === 'string'
54+ ? resolvedSearchParams . referrer
55+ : '' ,
56+ utmSource :
57+ typeof resolvedSearchParams . utm_source === 'string'
58+ ? resolvedSearchParams . utm_source
59+ : '' ,
60+ utmMedium :
61+ typeof resolvedSearchParams . utm_medium === 'string'
62+ ? resolvedSearchParams . utm_medium
63+ : '' ,
64+ utmCampaign :
65+ typeof resolvedSearchParams . utm_campaign === 'string'
66+ ? resolvedSearchParams . utm_campaign
67+ : '' ,
68+ utmContent :
69+ typeof resolvedSearchParams . utm_content === 'string'
70+ ? resolvedSearchParams . utm_content
71+ : '' ,
72+ } ,
73+ 'Freebuff login received non-CLI-shaped auth_code' ,
74+ )
75+ }
76+
2677 const { expiresAt } = parseAuthCode ( authCode )
2778
2879 if ( expiresAt && isAuthCodeExpired ( expiresAt ) ) {
0 commit comments