@@ -736,8 +736,6 @@ export const auth = betterAuth({
736736 tokenUrl : 'https://api.hubapi.com/oauth/v1/token' ,
737737 userInfoUrl : 'https://api.hubapi.com/oauth/v1/access-tokens' ,
738738 prompt : 'consent' ,
739- responseType : 'code' ,
740- overrideUserInfo : true ,
741739 scopes : [
742740 'crm.objects.contacts.read' ,
743741 'crm.objects.contacts.write' ,
@@ -773,13 +771,29 @@ export const auth = betterAuth({
773771 )
774772
775773 if ( ! response . ok ) {
774+ let errorBody : string | undefined
775+ try {
776+ errorBody = await response . text ( )
777+ } catch {
778+ // ignore
779+ }
776780 logger . error ( 'Failed to fetch HubSpot user info' , {
777781 status : response . status ,
782+ statusText : response . statusText ,
783+ body : errorBody ?. slice ( 0 , 500 ) ,
778784 } )
779785 throw new Error ( 'Failed to fetch user info' )
780786 }
781787
782- const data = await response . json ( )
788+ const rawText = await response . text ( )
789+ const data = JSON . parse ( rawText )
790+
791+ const scopesArray = Array . isArray ( ( data as any ) ?. scopes ) ? ( data as any ) . scopes : [ ]
792+ if ( Array . isArray ( scopesArray ) && scopesArray . length > 0 ) {
793+ tokens . scopes = scopesArray
794+ } else if ( typeof ( data as any ) ?. scope === 'string' ) {
795+ tokens . scopes = ( data as any ) . scope . split ( / \s + / ) . filter ( Boolean )
796+ }
783797
784798 logger . info ( 'HubSpot token metadata response:' , {
785799 hasScopes : ! ! data . scopes ,
0 commit comments