Skip to content

Commit

Permalink
fix(browser): remove session item after successful sign-in
Browse files Browse the repository at this point in the history
  • Loading branch information
charIeszhao committed Apr 28, 2022
1 parent 28ccd8e commit f33bcd2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/browser/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const mockedSignInUri = generateSignInUri({

const refreshTokenStorageKey = `logto:${appId}:refreshToken`;
const idTokenStorageKey = `logto:${appId}:idToken`;
const signInSessionStorageKey = `logto:${appId}`;

const accessToken = 'access_token_value';
const refreshToken = 'new_refresh_token_value';
Expand Down Expand Up @@ -200,11 +201,13 @@ describe('LogtoClient', () => {
const code = `code_value`;
const callbackUri = `${redirectUri}?code=${code}&state=${mockedState}&codeVerifier=${mockedCodeVerifier}`;

expect(sessionStorage.getItem(signInSessionStorageKey)).not.toBeNull();
await expect(logtoClient.handleSignInCallback(callbackUri)).resolves.not.toThrow();
await expect(logtoClient.getAccessToken()).resolves.toEqual(accessToken);
expect(localStorage.getItem(refreshTokenStorageKey)).toEqual(refreshToken);
expect(localStorage.getItem(idTokenStorageKey)).toEqual(idToken);
expect(requester).toHaveBeenCalledWith(tokenEndpoint, expect.anything());
expect(sessionStorage.getItem(signInSessionStorageKey)).toBeNull();
});
});

Expand Down
1 change: 1 addition & 0 deletions packages/browser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ export default class LogtoClient {
await this.verifyIdToken(codeTokenResponse.idToken);

this.saveCodeToken(codeTokenResponse);
this.signInSession = null;
}

public async signOut(postLogoutRedirectUri?: string) {
Expand Down

0 comments on commit f33bcd2

Please sign in to comment.