-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: hot fix for private route (#1381)
- Loading branch information
Pham Hai Duong
authored
May 28, 2020
1 parent
195c099
commit 75bd498
Showing
8 changed files
with
77 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,27 @@ | ||
import { removeSession } from './remove-session' | ||
import hardtack from 'hardtack' | ||
import { COOKIE_SESSION_KEY } from '../utils/cognito' | ||
import { mockRefreshParams } from '../__mocks__/cognito-session' | ||
|
||
const stringifiedMock = JSON.stringify(mockRefreshParams) | ||
|
||
describe('removeSession', () => { | ||
it('should remove a session cookie for a valid host', () => { | ||
window.location.hostname = 'something.reapit.com' | ||
hardtack.remove = jest.fn() | ||
it('should remove a session cookie', () => { | ||
window.localStorage.setItem(COOKIE_SESSION_KEY, stringifiedMock) | ||
|
||
expect(window.localStorage.getItem(COOKIE_SESSION_KEY)).toEqual(stringifiedMock) | ||
|
||
removeSession() | ||
|
||
expect(hardtack.remove).toHaveBeenCalledWith(COOKIE_SESSION_KEY, { | ||
path: '/', | ||
domain: window.location.hostname, | ||
}) | ||
expect(window.localStorage.getItem(COOKIE_SESSION_KEY)).toBeFalsy() | ||
}) | ||
|
||
it('should remove a session cookie with appEnv', () => { | ||
window.location.hostname = 'something.reapit.com' | ||
hardtack.remove = jest.fn() | ||
window.localStorage.setItem(`development-${COOKIE_SESSION_KEY}`, stringifiedMock) | ||
|
||
expect(window.localStorage.getItem(`development-${COOKIE_SESSION_KEY}`)).toEqual(stringifiedMock) | ||
|
||
removeSession(COOKIE_SESSION_KEY, 'development') | ||
|
||
expect(hardtack.remove).toHaveBeenCalledWith(`development-${COOKIE_SESSION_KEY}`, { | ||
path: '/', | ||
domain: window.location.hostname, | ||
}) | ||
expect(window.localStorage.getItem(COOKIE_SESSION_KEY)).toBeFalsy() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,7 @@ | ||
import { COOKIE_SESSION_KEY } from '../utils/cognito' | ||
import hardtack from 'hardtack' | ||
|
||
export const removeSession = (identifier: string = COOKIE_SESSION_KEY, appEnv?: string): void => { | ||
const identifierWithEnv = appEnv ? `${appEnv}-${identifier}` : identifier | ||
hardtack.remove(identifierWithEnv, { | ||
path: '/', | ||
domain: window.location.hostname, | ||
}) | ||
|
||
window.localStorage.removeItem(identifierWithEnv) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters