Skip to content

Commit ed9bb82

Browse files
committed
logout with www
1 parent 113467c commit ed9bb82

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

packages/eas-cli/src/user/SessionManager.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ export default class SessionManager {
8585
}
8686

8787
public async logoutAsync(): Promise<void> {
88+
const sessionSecret = this.getSessionSecret();
89+
if (sessionSecret) {
90+
const apiV2Client = new ApiV2Client({ accessToken: null, sessionSecret });
91+
try {
92+
await apiV2Client.postAsync('auth/logout', { body: {} });
93+
} catch {
94+
// Best-effort: clear the local session even if the server request fails
95+
}
96+
}
8897
this.currentActor = undefined;
8998
await this.setSessionAsync(undefined);
9099
}

packages/eas-cli/src/user/__tests__/SessionManager-test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,36 @@ describe(SessionManager, () => {
219219
await sessionManager.logoutAsync();
220220
expect(sessionManager['getSessionSecret']()).toBe(null);
221221
});
222+
223+
it('calls the server logout endpoint when session secret exists', async () => {
224+
jest.mocked(fetchSessionSecretAndUserAsync).mockResolvedValue({
225+
sessionSecret: 'SESSION_SECRET',
226+
id: 'USER_ID',
227+
username: 'USERNAME',
228+
});
229+
const apiV2PostSpy = jest.spyOn(ApiV2Client.prototype, 'postAsync');
230+
231+
const sessionManager = new SessionManager(analytics);
232+
await sessionManager['loginAsync']({ username: 'USERNAME', password: 'PASSWORD' });
233+
await sessionManager.logoutAsync();
234+
235+
expect(apiV2PostSpy).toHaveBeenCalledWith('auth/logout', { body: {} });
236+
});
237+
238+
it('clears the local session even if the server logout call fails', async () => {
239+
jest.mocked(fetchSessionSecretAndUserAsync).mockResolvedValue({
240+
sessionSecret: 'SESSION_SECRET',
241+
id: 'USER_ID',
242+
username: 'USERNAME',
243+
});
244+
jest.spyOn(ApiV2Client.prototype, 'postAsync').mockRejectedValueOnce(new Error('Network error'));
245+
246+
const sessionManager = new SessionManager(analytics);
247+
await sessionManager['loginAsync']({ username: 'USERNAME', password: 'PASSWORD' });
248+
await sessionManager.logoutAsync();
249+
250+
expect(sessionManager['getSessionSecret']()).toBe(null);
251+
});
222252
});
223253

224254
describe('showLoginPromptAsync', () => {

0 commit comments

Comments
 (0)