Skip to content

Commit

Permalink
move localStorage to a cookieg (#954)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryelo authored Sep 10, 2020
1 parent 1029aea commit 13c30ad
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/js/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default () => {
// on every page load
if (token && token.length > 10) {
options.token = token;
options.refreshToken = getWindow().localStorage.getItem(options.cookieName);
options.refreshToken = cookie.get('cs_jwt_refresh');
}

const promise = jwt.init(options).then(bouncer);
Expand Down
7 changes: 6 additions & 1 deletion src/js/jwt/jwt.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ function isExistingValid(token) {
function initSuccess() {
log('JWT Initialized');
setCookie(priv.keycloak.token);
window.localStorage.setItem(priv.cookie.cookieName, priv.keycloak.refreshToken);
setRefresh(priv.keycloak.refreshToken);
}

// keycloak init failed
Expand Down Expand Up @@ -322,6 +322,11 @@ function setCookie(token) {
}
}

function setRefresh(refreshToken) {
log('Setting the refresh token');
cookie.set('cs_jwt_refresh', refreshToken, { secure: true });
}

// do this so we can mock out for test
function setCookieWrapper(str) {
document.cookie = str;
Expand Down
4 changes: 0 additions & 4 deletions src/js/jwt/jwt.unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,6 @@ describe('JWT', () => {
describe('init and auth functions', () => {
describe('initSuccess()', () => {
const initSuccess = jwt.__get__('initSuccess');
test('should write to localStorage', () => {
initSuccess();
expect(window.localStorage.getItem('cs_jwt')).toContain(encodedToken);
});
test('should set a cookie', () => {
const mockSetCookie = jest.fn();
jwt.__set__('setCookie', mockSetCookie);
Expand Down

0 comments on commit 13c30ad

Please sign in to comment.