minor style tweaks and refresh token fixes

This commit is contained in:
Danny Coates 2020-07-24 22:04:42 -07:00
parent 4674666807
commit 5c5853c645
No known key found for this signature in database
GPG Key ID: 4C442633C62E00CB
3 changed files with 28 additions and 28 deletions

View File

@ -6,7 +6,7 @@ module.exports = function(state, emit) {
class="absolute inset-0 flex items-center justify-center overflow-hidden z-40 bg-white md:rounded-xl md:my-8 dark:bg-grey-90" class="absolute inset-0 flex items-center justify-center overflow-hidden z-40 bg-white md:rounded-xl md:my-8 dark:bg-grey-90"
> >
<div <div
class="h-full w-full max-h-screen absolute top-0 flex items-center justify-center" class="h-full w-full max-h-screen absolute top-0 flex justify-center md:items-center"
> >
<div class="w-full"> <div class="w-full">
${state.modal(state, emit, close)} ${state.modal(state, emit, close)}

View File

@ -1,16 +1,15 @@
const html = require('choo/html'); const html = require('choo/html');
const assets = require('../../common/assets'); const assets = require('../../common/assets');
const { bytes, platform } = require('../utils'); const { bytes } = require('../utils');
const { canceledSignup, submittedSignup } = require('../metrics'); const { canceledSignup, submittedSignup } = require('../metrics');
module.exports = function(trigger) { module.exports = function(trigger) {
return function(state, emit, close) { return function(state, emit, close) {
const DAYS = Math.floor(state.LIMITS.MAX_EXPIRE_SECONDS / 86400); const DAYS = Math.floor(state.LIMITS.MAX_EXPIRE_SECONDS / 86400);
const hidden = platform() === 'android' ? 'hidden' : '';
let submitting = false; let submitting = false;
return html` return html`
<send-signup-dialog <send-signup-dialog
class="flex flex-col lg:flex-row justify-center px-8 md:px-24 w-full h-full" class="flex flex-col lg:flex-row justify-center my-16 md:my-0 px-8 md:px-24 w-full h-full"
> >
<img src="${assets.get('master-logo.svg')}" class="h-16 mt-1 mb-4" /> <img src="${assets.get('master-logo.svg')}" class="h-16 mt-1 mb-4" />
<section <section
@ -32,7 +31,6 @@ module.exports = function(trigger) {
${state.translate('accountBenefitTimeLimit', { count: DAYS })} ${state.translate('accountBenefitTimeLimit', { count: DAYS })}
</li> </li>
<li>${state.translate('accountBenefitSync')}</li> <li>${state.translate('accountBenefitSync')}</li>
<li>${state.translate('accountBenefitMoz')}</li>
</ul> </ul>
</section> </section>
<section <section
@ -42,7 +40,7 @@ module.exports = function(trigger) {
<input <input
id="email-input" id="email-input"
type="email" type="email"
class="${hidden} border rounded-lg w-full px-2 py-1 h-12 mb-3 text-lg text-grey-70 leading-loose dark:bg-grey-80 dark:text-white" class="hidden lg:block border rounded-lg w-full px-2 py-1 h-12 mb-3 text-lg text-grey-70 leading-loose dark:bg-grey-80 dark:text-white"
placeholder=${state.translate('emailPlaceholder')} placeholder=${state.translate('emailPlaceholder')}
/> />
<input <input

View File

@ -223,12 +223,17 @@ export default class User {
refresh_token: this.refreshToken refresh_token: this.refreshToken
}) })
}); });
const auth = await tokenResponse.json(); if (tokenResponse.ok) {
this.info.access_token = auth.access_token; const auth = await tokenResponse.json();
return true; const info = { ...this.info, access_token: auth.access_token };
this.info = info;
return true;
}
} catch (e) { } catch (e) {
return false; console.error(e);
} }
await this.logout();
return false;
} }
async logout() { async logout() {
@ -272,29 +277,24 @@ export default class User {
const key = b64ToArray(this.info.fileListKey); const key = b64ToArray(this.info.fileListKey);
const sha = await crypto.subtle.digest('SHA-256', key); const sha = await crypto.subtle.digest('SHA-256', key);
const kid = arrayToB64(new Uint8Array(sha)).substring(0, 16); const kid = arrayToB64(new Uint8Array(sha)).substring(0, 16);
async function retry(e) { const retry = async () => {
if (e.message === '401') { const refreshed = await this.refresh();
const refreshed = await this.refresh(); if (refreshed) {
if (refreshed) { return await this.syncFileList();
return await this.syncFileList(); } else {
} else { return { incoming: true };
await this.logout();
return { incoming: true };
}
} }
} };
try { try {
const encrypted = await getFileList( const encrypted = await getFileList(this.bearerToken, kid);
this.bearerToken,
this.refreshToken,
kid
);
const decrypted = await streamToArrayBuffer( const decrypted = await streamToArrayBuffer(
decryptStream(blobStream(encrypted), key) decryptStream(blobStream(encrypted), key)
); );
list = JSON.parse(textDecoder.decode(decrypted)); list = JSON.parse(textDecoder.decode(decrypted));
} catch (e) { } catch (e) {
return retry(e); if (e.message === '401') {
return retry(e);
}
} }
changes = await this.storage.merge(list); changes = await this.storage.merge(list);
if (!changes.outgoing) { if (!changes.outgoing) {
@ -307,9 +307,11 @@ export default class User {
const encrypted = await streamToArrayBuffer( const encrypted = await streamToArrayBuffer(
encryptStream(blobStream(blob), key) encryptStream(blobStream(blob), key)
); );
await setFileList(this.bearerToken, this.refreshToken, kid, encrypted); await setFileList(this.bearerToken, kid, encrypted);
} catch (e) { } catch (e) {
return retry(e); if (e.message === '401') {
return retry(e);
}
} }
return changes; return changes;
} }