From d6ad46eb22721e7c1386054ea8fa4b86ae4aa3a8 Mon Sep 17 00:00:00 2001 From: Mike Lewis Date: Fri, 1 Oct 2021 12:43:32 +0100 Subject: [PATCH] core-app-api: do not call connector.removeSession in StaticAuthSessionManager.removeSession Signed-off-by: Mike Lewis --- .changeset/sixty-shrimps-kneel.md | 6 ++++++ .../StaticAuthSessionManager.test.ts | 14 ++++++++++++-- .../AuthSessionManager/StaticAuthSessionManager.ts | 7 ++++++- 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 .changeset/sixty-shrimps-kneel.md diff --git a/.changeset/sixty-shrimps-kneel.md b/.changeset/sixty-shrimps-kneel.md new file mode 100644 index 0000000000..7804e8de11 --- /dev/null +++ b/.changeset/sixty-shrimps-kneel.md @@ -0,0 +1,6 @@ +--- +'@backstage/core-app-api': patch +--- + +Stop calling connector.removeSession in StaticAuthSessionManager, instead just discarding the +session locally. diff --git a/packages/core-app-api/src/lib/AuthSessionManager/StaticAuthSessionManager.test.ts b/packages/core-app-api/src/lib/AuthSessionManager/StaticAuthSessionManager.test.ts index 26f489a1b4..49e9bf501f 100644 --- a/packages/core-app-api/src/lib/AuthSessionManager/StaticAuthSessionManager.test.ts +++ b/packages/core-app-api/src/lib/AuthSessionManager/StaticAuthSessionManager.test.ts @@ -83,7 +83,7 @@ describe('StaticAuthSessionManager', () => { expect(createSession).toHaveBeenCalledTimes(2); }); - it('should remove session and reload', async () => { + it('should clear the local session', async () => { const removeSession = jest.fn(); const manager = new StaticAuthSessionManager({ connector: { removeSession }, @@ -91,7 +91,17 @@ describe('StaticAuthSessionManager', () => { } as any); await manager.removeSession(); - expect(removeSession).toHaveBeenCalled(); expect(await manager.getSession({ optional: true })).toBe(undefined); }); + + it('should not remove the session via the connector', async () => { + const removeSession = jest.fn(); + const manager = new StaticAuthSessionManager({ + connector: { removeSession }, + ...defaultOptions, + } as any); + + await manager.removeSession(); + expect(removeSession).not.toHaveBeenCalled(); + }); }); diff --git a/packages/core-app-api/src/lib/AuthSessionManager/StaticAuthSessionManager.ts b/packages/core-app-api/src/lib/AuthSessionManager/StaticAuthSessionManager.ts index b7940d88c4..fd02e4b2df 100644 --- a/packages/core-app-api/src/lib/AuthSessionManager/StaticAuthSessionManager.ts +++ b/packages/core-app-api/src/lib/AuthSessionManager/StaticAuthSessionManager.ts @@ -71,9 +71,14 @@ export class StaticAuthSessionManager implements MutableSessionManager { return this.currentSession; } + /** + * We don't call this.connector.removeSession here, since this session manager + * is intended to be static. As such there's no need to hit the remote logout + * endpoint - simply discarding the local session state when signing out is + * enough. + */ async removeSession() { this.currentSession = undefined; - await this.connector.removeSession(); this.stateTracker.setIsSignedIn(false); }