Skip to content

Commit

Permalink
Merge pull request #1646 from immutable/feature/ID-1538-fix-magic-log…
Browse files Browse the repository at this point in the history
…out-issue

fix: ID-1538 Resolved issue with redirect logout not logging out of Magic
  • Loading branch information
haydenfowler committed Apr 5, 2024
2 parents 545c6e7 + 05a8cd5 commit abf4b95
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
26 changes: 21 additions & 5 deletions packages/passport/sdk/src/Passport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,28 @@ describe('Passport', () => {
});

describe('logout', () => {
it('should execute logout without error', async () => {
await passport.logout();
describe('when the logout mode is silent', () => {
it('should execute logout without error', async () => {
await passport.logout();

expect(logoutMock).toBeCalledTimes(1);
expect(magicLogoutMock).toBeCalledTimes(1);
expect(confirmationLogoutMock).toBeCalledTimes(1);
expect(logoutMock).toBeCalledTimes(1);
expect(magicLogoutMock).toBeCalledTimes(1);
expect(confirmationLogoutMock).toBeCalledTimes(1);
});
});

describe('when the logout mode is redirect', () => {
it('should execute logout without error in the correct order', async () => {
await passport.logout();

const logoutMockOrder = logoutMock.mock.invocationCallOrder[0];
const magicLogoutMockOrder = magicLogoutMock.mock.invocationCallOrder[0];

expect(confirmationLogoutMock).toBeCalledTimes(1);
expect(logoutMock).toBeCalledTimes(1);
expect(magicLogoutMock).toBeCalledTimes(1);
expect(magicLogoutMockOrder).toBeLessThan(logoutMockOrder);
});
});
});

Expand Down
16 changes: 12 additions & 4 deletions packages/passport/sdk/src/Passport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,18 @@ export class Passport {
} catch (err) {
logger.warn('Failed to logout from confirmation screen', err);
}
await Promise.allSettled([
this.authManager.logout(),
this.magicAdapter.logout(),
]);

if (this.config.oidcConfiguration.logoutMode === 'silent') {
await Promise.allSettled([
this.authManager.logout(),
this.magicAdapter.logout(),
]);
} else {
// We need to ensure that the Magic wallet is logged out BEFORE redirecting
await this.magicAdapter.logout();
await this.authManager.logout();
}

this.passportEventEmitter.emit(PassportEvents.LOGGED_OUT);
}

Expand Down

0 comments on commit abf4b95

Please sign in to comment.