@@ -11,9 +11,10 @@ export async function getStravaAccessToken(creds?: { clientId?: string; clientSe
1111 // Check if we received any non-empty credentials in the UI object
1212 const hasUICreds = ! ! ( creds && ( creds . clientId || creds . clientSecret || creds . refreshToken ) ) ;
1313
14- const clientId = ( creds ?. clientId ) || process . env . STRAVA_CLIENT_ID ;
15- const clientSecret = ( creds ?. clientSecret ) || process . env . STRAVA_CLIENT_SECRET ;
16- const refreshToken = ( creds ?. refreshToken ) || process . env . STRAVA_REFRESH_TOKEN ;
14+ // Use UI value if present (even if empty string, but we trim first), otherwise fallback to ENV
15+ const clientId = ( creds ?. clientId ?. trim ( ) || process . env . STRAVA_CLIENT_ID ?. trim ( ) ) ;
16+ const clientSecret = ( creds ?. clientSecret ?. trim ( ) || process . env . STRAVA_CLIENT_SECRET ?. trim ( ) ) ;
17+ const refreshToken = ( creds ?. refreshToken ?. trim ( ) || process . env . STRAVA_REFRESH_TOKEN ?. trim ( ) ) ;
1718
1819 const source = hasUICreds ? 'UI' : 'ENV' ;
1920 console . log ( `[Strava] Attempting token refresh. Source: ${ source } , ClientID: ${ clientId ?. substring ( 0 , 5 ) } ..., Token: ${ refreshToken ?. substring ( 0 , 8 ) } ...` ) ;
@@ -50,16 +51,21 @@ export async function getStravaAccessToken(creds?: { clientId?: string; clientSe
5051 }
5152
5253 const data = await response . json ( ) ;
53- const scopes = data . scope || 'NOT_RETURNED' ;
54- console . log ( `[Strava] Refresh successful. Scopes received: ${ scopes } . Response keys: ${ Object . keys ( data ) . join ( ', ' ) } ` ) ;
54+ const responseKeys = Object . keys ( data ) ;
55+ const receivedScope = data . scope || 'NOT_RETURNED' ;
56+
57+ console . log ( `[Strava] Refresh successful. Response Keys: ${ responseKeys . join ( ', ' ) } ` ) ;
58+ console . log ( `[Strava] Scope in response: ${ receivedScope } ` ) ;
5559
5660 if ( ! data . access_token ) {
5761 throw new Error ( 'Strava token refresh response did not contain an access_token' ) ;
5862 }
5963
6064 // Check for activity read permission in the scopes
61- if ( scopes !== 'NOT_RETURNED' && ! scopes . includes ( 'activity:read' ) ) {
62- console . warn ( `[Strava] WARNING: Token refreshed but missing 'activity:read' scope. Current permitted scopes: ${ scopes } ` ) ;
65+ if ( receivedScope !== 'NOT_RETURNED' && ! receivedScope . includes ( 'activity:read' ) ) {
66+ console . warn ( `[Strava] WARNING: Token refreshed but missing 'activity:read' scope. Current permitted scopes: ${ receivedScope } ` ) ;
67+ } else if ( receivedScope === 'NOT_RETURNED' ) {
68+ console . log ( `[Strava] Note: No scope returned in refresh response. This usually means scopes remain unchanged.` ) ;
6369 }
6470
6571 return data . access_token ;
0 commit comments