added oauth refresh token support

Co-authored-by: timvisee <tim@visee.me>
This commit is contained in:
Danny Coates 2020-07-24 18:11:50 -07:00 committed by timvisee
parent b15c017dcd
commit 4f273eca03
No known key found for this signature in database
GPG key ID: B8DB720BC383E172
8 changed files with 118 additions and 27 deletions

View file

@ -49,8 +49,8 @@ export default function(state, emitter) {
state.user.login(email);
});
emitter.on('logout', () => {
state.user.logout();
emitter.on('logout', async () => {
await state.user.logout();
metrics.loggedOut({ trigger: 'button' });
emitter.emit('pushState', '/');
});
@ -178,6 +178,12 @@ export default function(state, emitter) {
//cancelled. do nothing
metrics.cancelledUpload(archive, err.duration);
render();
} else if (err.message === '401') {
const refreshed = await state.user.refresh();
if (refreshed) {
return emitter.emit('upload');
}
emitter.emit('pushState', '/error');
} else {
// eslint-disable-next-line no-console
console.error(err);