@@ -15,6 +15,10 @@ import GitHubProvider from 'next-auth/providers/github'
1515import type { NextAuthOptions } from 'next-auth'
1616import type { Adapter } from 'next-auth/adapters'
1717
18+ import {
19+ getCliAuthCodeHashPrefix ,
20+ isCliAuthCodeCandidate ,
21+ } from '@/app/onboard/_helpers'
1822import { logger } from '@/util/logger'
1923
2024async 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 )
0 commit comments