Remove evil auth cache
This commit is contained in:
parent
1c71983610
commit
736b8045aa
1 changed files with 2 additions and 14 deletions
|
@ -22,8 +22,6 @@ import MatrixClientPeg from '../../../MatrixClientPeg';
|
||||||
import { _t } from '../../../languageHandler';
|
import { _t } from '../../../languageHandler';
|
||||||
import Modal from '../../../Modal';
|
import Modal from '../../../Modal';
|
||||||
|
|
||||||
const AUTH_CACHE_AGE = 5 * 60 * 1000; // 5 minutes
|
|
||||||
|
|
||||||
export default class DevicesPanel extends React.Component {
|
export default class DevicesPanel extends React.Component {
|
||||||
constructor(props, context) {
|
constructor(props, context) {
|
||||||
super(props, context);
|
super(props, context);
|
||||||
|
@ -109,16 +107,11 @@ export default class DevicesPanel extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
_onDeleteClick() {
|
_onDeleteClick() {
|
||||||
if (this.context.authCache.lastUpdate < Date.now() - AUTH_CACHE_AGE) {
|
|
||||||
this.context.authCache.auth = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
deleting: true,
|
deleting: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
// try with auth cache (which is null, so no interactive auth, to start off)
|
this._makeDeleteRequest(null).catch((error) => {
|
||||||
this._makeDeleteRequest(this.context.authCache.auth).catch((error) => {
|
|
||||||
if (this._unmounted) { return; }
|
if (this._unmounted) { return; }
|
||||||
if (error.httpStatus !== 401 || !error.data || !error.data.flows) {
|
if (error.httpStatus !== 401 || !error.data || !error.data.flows) {
|
||||||
// doesn't look like an interactive-auth failure
|
// doesn't look like an interactive-auth failure
|
||||||
|
@ -145,14 +138,12 @@ export default class DevicesPanel extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
_makeDeleteRequest(auth) {
|
_makeDeleteRequest(auth) {
|
||||||
this.context.authCache.auth = auth;
|
|
||||||
this.context.authCache.lastUpdate = Date.now();
|
|
||||||
return MatrixClientPeg.get().deleteMultipleDevices(this.state.selectedDevices, auth).then(
|
return MatrixClientPeg.get().deleteMultipleDevices(this.state.selectedDevices, auth).then(
|
||||||
() => {
|
() => {
|
||||||
// Remove the deleted devices from `devices`, reset selection to []
|
// Remove the deleted devices from `devices`, reset selection to []
|
||||||
this.setState({
|
this.setState({
|
||||||
devices: this.state.devices.filter(
|
devices: this.state.devices.filter(
|
||||||
(d) => !this.state.selectedDevices.includes(d.device_id)
|
(d) => !this.state.selectedDevices.includes(d.device_id),
|
||||||
),
|
),
|
||||||
selectedDevices: [],
|
selectedDevices: [],
|
||||||
});
|
});
|
||||||
|
@ -218,6 +209,3 @@ DevicesPanel.displayName = 'MemberDeviceInfo';
|
||||||
DevicesPanel.propTypes = {
|
DevicesPanel.propTypes = {
|
||||||
className: React.PropTypes.string,
|
className: React.PropTypes.string,
|
||||||
};
|
};
|
||||||
DevicesPanel.contextTypes = {
|
|
||||||
authCache: React.PropTypes.object,
|
|
||||||
};
|
|
||||||
|
|
Loading…
Reference in a new issue