Skip to content

Commit 3bde8bb

Browse files
committed
logout with www
1 parent 113467c commit 3bde8bb

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,38 @@ 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
245+
.spyOn(ApiV2Client.prototype, 'postAsync')
246+
.mockRejectedValueOnce(new Error('Network error'));
247+
248+
const sessionManager = new SessionManager(analytics);
249+
await sessionManager['loginAsync']({ username: 'USERNAME', password: 'PASSWORD' });
250+
await sessionManager.logoutAsync();
251+
252+
expect(sessionManager['getSessionSecret']()).toBe(null);
253+
});
222254
});
223255

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

0 commit comments

Comments
 (0)