Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport of Bug Fix: Surface Error for when cookie settings prevent localStorage into release/1.14.x #21665

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/21503.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
ui: Surface DOMException error when browser settings prevent localStorage.
```
16 changes: 15 additions & 1 deletion ui/app/lib/local-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,22 @@
*/

export default {
isLocalStorageSupported() {
try {
const key = `__storage__test`;
window.localStorage.setItem(key, null);
window.localStorage.removeItem(key);
return true;
} catch (e) {
// modify the e object so we can customize the error message.
// e.message is readOnly.
e.errors = [`This is likely due to your browser's cookie settings.`];
throw e;
}
},

getItem(key) {
var item = window.localStorage.getItem(key);
const item = window.localStorage.getItem(key);
return item && JSON.parse(item);
},

Expand Down
4 changes: 4 additions & 0 deletions ui/app/routes/vault/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Route from '@ember/routing/route';
import { task, timeout } from 'ember-concurrency';
import Ember from 'ember';
import getStorage from '../../lib/token-storage';
import localStorage from 'vault/lib/local-storage';
import ClusterRoute from 'vault/mixins/cluster-route';
import ModelBoundaryRoute from 'vault/mixins/model-boundary-route';

Expand Down Expand Up @@ -87,6 +88,9 @@ export default Route.extend(ModelBoundaryRoute, ClusterRoute, {
},

model(params) {
// if a user's browser settings block localStorage they will be unable to use Vault. The method will throw the error and the rest of the application will not load.
localStorage.isLocalStorageSupported();

const id = this.getClusterId(params);
return this.store.findRecord('cluster', id);
},
Expand Down