Handle invalid RS auth tokens
This commit is contained in:
parent
ab637deb33
commit
ab9ad2f354
@ -1,5 +1,36 @@
|
|||||||
import Route from '@ember/routing/route';
|
import Route from '@ember/routing/route';
|
||||||
|
import { inject as service } from '@ember/service';
|
||||||
import BodyClassMixin from 'ember-body-class/mixins/body-class';
|
import BodyClassMixin from 'ember-body-class/mixins/body-class';
|
||||||
|
|
||||||
export default Route.extend(BodyClassMixin, {
|
export default Route.extend(BodyClassMixin, {
|
||||||
|
|
||||||
|
storage: service(),
|
||||||
|
|
||||||
|
beforeModel () {
|
||||||
|
this.get('storage.rs').on('error', (error) => {
|
||||||
|
console.debug('rs.on error', error);
|
||||||
|
if (error.name === 'Unauthorized') {
|
||||||
|
this.handleUnauthorized();
|
||||||
|
} else {
|
||||||
|
alert('An unknown error occured. Please check the browser console for details.');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// We need to handle this here, so we can transitionTo
|
||||||
|
// the connect route
|
||||||
|
handleUnauthorized () {
|
||||||
|
// Ignore additional unauthorized events after the
|
||||||
|
// first one
|
||||||
|
if (this.get('storage.unauthorized')) { return; }
|
||||||
|
|
||||||
|
this.get('storage').setProperties({
|
||||||
|
unauthorized: true,
|
||||||
|
connecting: false,
|
||||||
|
connected: false
|
||||||
|
});
|
||||||
|
|
||||||
|
this.transitionTo('connect');
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import EmberObject from '@ember/object';
|
import EmberObject from '@ember/object';
|
||||||
import { computed, observer } from '@ember/object';
|
|
||||||
import Service from '@ember/service';
|
import Service from '@ember/service';
|
||||||
|
import { computed, observer } from '@ember/object';
|
||||||
|
import { isEmpty } from '@ember/utils';
|
||||||
import RemoteStorage from 'npm:remotestoragejs';
|
import RemoteStorage from 'npm:remotestoragejs';
|
||||||
import Widget from 'npm:remotestorage-widget';
|
import Widget from 'npm:remotestorage-widget';
|
||||||
import simpleContentType from 'inspektor/utils/simple-content-type';
|
import simpleContentType from 'inspektor/utils/simple-content-type';
|
||||||
@ -11,6 +12,7 @@ export default Service.extend({
|
|||||||
widget: null,
|
widget: null,
|
||||||
connecting: true,
|
connecting: true,
|
||||||
connected: false,
|
connected: false,
|
||||||
|
unauthorized: false,
|
||||||
userAddress: null,
|
userAddress: null,
|
||||||
disconnected: computed.not('connected'),
|
disconnected: computed.not('connected'),
|
||||||
client: null,
|
client: null,
|
||||||
@ -101,6 +103,8 @@ export default Service.extend({
|
|||||||
let items = [];
|
let items = [];
|
||||||
|
|
||||||
return this.get('client').getListing(path).then(listing => {
|
return this.get('client').getListing(path).then(listing => {
|
||||||
|
if (isEmpty(listing)) { return []; }
|
||||||
|
|
||||||
Object.keys(listing).forEach(name => {
|
Object.keys(listing).forEach(name => {
|
||||||
let item = listing[name];
|
let item = listing[name];
|
||||||
let type = item['Content-Type'] || 'folder';
|
let type = item['Content-Type'] || 'folder';
|
||||||
|
@ -1 +0,0 @@
|
|||||||
{{outlet}}
|
|
Loading…
x
Reference in New Issue
Block a user