Skip to content

Commit

Permalink
UI/revert backport session storage (#16169)
Browse files Browse the repository at this point in the history
* Revert "UI: Switch usage of localStorage to sessionStorage (#14054)"

This reverts commit 1aa506e.

* remove other sessionStorage

* changelog

* keep old changelog
  • Loading branch information
Monkeychip authored Jun 28, 2022
1 parent 32b4d1b commit 624f8b4
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion changelog/14054.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```release-note:improvement
ui: Swap browser localStorage in favor of sessionStorage
```
```
3 changes: 3 additions & 0 deletions changelog/16169.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
ui: Revert using localStorage in favor of sessionStorage
```
8 changes: 4 additions & 4 deletions ui/app/lib/local-storage.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
export default {
getItem(key) {
var item = window.sessionStorage.getItem(key);
var item = window.localStorage.getItem(key);
return item && JSON.parse(item);
},

setItem(key, val) {
window.sessionStorage.setItem(key, JSON.stringify(val));
window.localStorage.setItem(key, JSON.stringify(val));
},

removeItem(key) {
return window.sessionStorage.removeItem(key);
return window.localStorage.removeItem(key);
},

keys() {
return Object.keys(window.sessionStorage);
return Object.keys(window.localStorage);
},
};
2 changes: 1 addition & 1 deletion ui/app/lib/token-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default function (type) {
}
let storage;
try {
localStorageWrapper.getItem('test');
window.localStorage.getItem('test');
storage = localStorageWrapper;
} catch (e) {
storage = memoryStorage;
Expand Down
8 changes: 4 additions & 4 deletions ui/app/services/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,8 @@ export default Service.extend({
},

async authSuccess(options, response) {
// persist selectedAuth to sessionStorage to rehydrate auth form on logout
sessionStorage.setItem('selectedAuth', options.selectedAuth);
// persist selectedAuth to localStorage to rehydrate auth form on logout
localStorage.setItem('selectedAuth', options.selectedAuth);
const authData = await this.persistAuthData(options, response, this.namespaceService.path);
await this.permissions.getPaths.perform();
return authData;
Expand All @@ -409,8 +409,8 @@ export default Service.extend({
},

getAuthType() {
// check sessionStorage first
const selectedAuth = sessionStorage.getItem('selectedAuth');
// check localStorage first
const selectedAuth = localStorage.getItem('selectedAuth');
if (selectedAuth) return selectedAuth;
// fallback to authData which discerns backend type from token
return this.authData ? this.authData.backend.type : null;
Expand Down
2 changes: 1 addition & 1 deletion ui/tests/acceptance/enterprise-control-groups-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ module('Acceptance | Enterprise | control groups', function (hooks) {
await authPage.login(context.userToken);
await settled();
if (shouldStoreToken) {
sessionStorage.setItem(
localStorage.setItem(
storageKey(accessor, 'kv/foo'),
JSON.stringify({
accessor,
Expand Down
2 changes: 1 addition & 1 deletion ui/tests/acceptance/oidc-auth-method-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module('Acceptance | oidc auth method', function (hooks) {
auth: { client_token: 'root' },
}));
// ensure clean state
sessionStorage.removeItem('selectedAuth');
localStorage.removeItem('selectedAuth');
});
hooks.afterEach(function () {
this.openStub.restore();
Expand Down
2 changes: 1 addition & 1 deletion ui/tests/acceptance/redirect-to-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module('Acceptance | redirect_to query param functionality', function (hooks) {
// normally we'd use the auth.logout helper to visit the route and reset the app, but in this case that
// also routes us to the auth page, and then all of the transitions from the auth page get redirected back
// to the auth page resulting in no redirect_to query param being set
sessionStorage.clear();
localStorage.clear();
});
test('redirect to a route after authentication', async function (assert) {
let url = '/vault/secrets/secret/create';
Expand Down
2 changes: 1 addition & 1 deletion ui/tests/pages/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default create({
await this.logout();
await settled();
// clear session storage to ensure we have a clean state
window.sessionStorage.clear();
window.localStorage.clear();
await this.visit({ with: 'token' });
await settled();
if (token) {
Expand Down

0 comments on commit 624f8b4

Please sign in to comment.