Handle invalid RS auth tokens

This commit is contained in:
Basti 2017-12-31 13:35:25 +01:00
parent ab637deb33
commit ab9ad2f354
3 changed files with 36 additions and 2 deletions

View File

@ -1,5 +1,36 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import BodyClassMixin from 'ember-body-class/mixins/body-class';
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');
}
});

View File

@ -1,6 +1,7 @@
import EmberObject from '@ember/object';
import { computed, observer } from '@ember/object';
import Service from '@ember/service';
import { computed, observer } from '@ember/object';
import { isEmpty } from '@ember/utils';
import RemoteStorage from 'npm:remotestoragejs';
import Widget from 'npm:remotestorage-widget';
import simpleContentType from 'inspektor/utils/simple-content-type';
@ -11,6 +12,7 @@ export default Service.extend({
widget: null,
connecting: true,
connected: false,
unauthorized: false,
userAddress: null,
disconnected: computed.not('connected'),
client: null,
@ -101,6 +103,8 @@ export default Service.extend({
let items = [];
return this.get('client').getListing(path).then(listing => {
if (isEmpty(listing)) { return []; }
Object.keys(listing).forEach(name => {
let item = listing[name];
let type = item['Content-Type'] || 'folder';

View File

@ -1 +0,0 @@
{{outlet}}