File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -682,6 +682,32 @@ describe('getAuthStatus', () => {
682682 } )
683683 } )
684684
685+ it ( 'canonicalizes legacy agentrelay.dev stored tokens before refreshing auth status' , async ( ) => {
686+ writeAuthJson ( userDataDir , {
687+ accessToken : 'cld_at_legacy_status' ,
688+ refreshToken : 'cld_rt_legacy_status' ,
689+ apiUrl : 'https://agentrelay.dev/cloud'
690+ } )
691+ mock . fetchMock . mockResolvedValue ( {
692+ ok : true ,
693+ status : 200 ,
694+ statusText : 'OK' ,
695+ json : async ( ) => ( { user : { id : 'user-legacy' } } )
696+ } )
697+
698+ const { getAuthStatus } = await import ( './auth' )
699+
700+ await expect ( getAuthStatus ( ) ) . resolves . toEqual ( {
701+ loggedIn : true ,
702+ apiUrl : 'https://agentrelay.com/cloud' ,
703+ user : { username : 'user-legacy' }
704+ } )
705+ expect ( mock . fetchMock ) . toHaveBeenCalledWith (
706+ 'https://agentrelay.com/cloud/api/v1/auth/whoami' ,
707+ expect . any ( Object )
708+ )
709+ } )
710+
685711 it ( 'hydrates a sparse stored profile from whoami' , async ( ) => {
686712 writeAuthJson ( userDataDir , {
687713 accessToken : 'cld_at_sparse_user' ,
Original file line number Diff line number Diff line change @@ -229,8 +229,9 @@ function loadTokens(): StoredTokens | null {
229229 const decrypted = safeStorage . decryptString ( raw )
230230 const parsed = StoredTokensSchema . safeParse ( JSON . parse ( decrypted ) )
231231 if ( ! parsed . success ) return null
232- saveAuthMeta ( parsed . data )
233- return parsed . data
232+ const tokens = { ...parsed . data , apiUrl : normalizeCloudApiUrl ( parsed . data . apiUrl ) }
233+ saveAuthMeta ( tokens )
234+ return tokens
234235 } catch {
235236 return null
236237 }
@@ -602,7 +603,7 @@ function cloudAuthFromStored(tokens: StoredTokens): CloudAuth {
602603}
603604
604605function normalizeCloudApiUrl ( url : string | undefined ) : string {
605- const normalized = ( url || getApiUrl ( ) ) . trim ( ) . replace ( / \/ + $ / , '' )
606+ const normalized = ( url || CLOUD_API_URL ) . trim ( ) . replace ( / \/ + $ / , '' )
606607 if ( normalized === LEGACY_CLOUD_API_URL ) return CLOUD_API_URL
607608 return normalized
608609}
You can’t perform that action at this time.
0 commit comments