diff --git a/packages/core-app-api/src/lib/AuthSessionManager/AuthSessionStore.test.ts b/packages/core-app-api/src/lib/AuthSessionManager/AuthSessionStore.test.ts index 4ceadd51ba..ded26c59e5 100644 --- a/packages/core-app-api/src/lib/AuthSessionManager/AuthSessionStore.test.ts +++ b/packages/core-app-api/src/lib/AuthSessionManager/AuthSessionStore.test.ts @@ -128,6 +128,19 @@ describe('GheAuth AuthSessionStore', () => { expect(manager.removeSession).toHaveBeenCalled(); }); + it('should set session', async () => { + const manager = new MockManager(); + const store = new AuthSessionStore({ manager, ...defaultOptions }); + + await expect(store.getSession({ optional: true })).resolves.toBe(undefined); + expect(localStorage.getItem('my-key')).toBe(null); + expect(manager.setSession).not.toHaveBeenCalled(); + store.setSession('123'); + expect(manager.setSession).toHaveBeenCalled(); + expect(localStorage.getItem('my-key')).toBe('"123"'); + await expect(store.getSession({ optional: true })).resolves.toBe('123'); + }); + it('should forward sessionState calls', () => { const manager = new MockManager(); const store = new AuthSessionStore({ manager, ...defaultOptions }); diff --git a/packages/core-app-api/src/lib/AuthSessionManager/AuthSessionStore.ts b/packages/core-app-api/src/lib/AuthSessionManager/AuthSessionStore.ts index 057a70e58d..fc15da7af8 100644 --- a/packages/core-app-api/src/lib/AuthSessionManager/AuthSessionStore.ts +++ b/packages/core-app-api/src/lib/AuthSessionManager/AuthSessionStore.ts @@ -15,7 +15,6 @@ */ import { - SessionManager, MutableSessionManager, SessionScopesFunc, SessionShouldRefreshFunc, @@ -40,7 +39,7 @@ type Options = { * * Session is serialized to JSON with special support for following types: Set. */ -export class AuthSessionStore implements SessionManager { +export class AuthSessionStore implements MutableSessionManager { private readonly manager: MutableSessionManager; private readonly storageKey: string; private readonly sessionShouldRefreshFunc: SessionShouldRefreshFunc; @@ -63,6 +62,11 @@ export class AuthSessionStore implements SessionManager { }); } + setSession(session: T | undefined): void { + this.manager.setSession(session); + this.saveSession(session); + } + async getSession(options: GetSessionOptions): Promise { const { scopes } = options; const session = this.loadSession();