From 3f0a656a36f3efa49ec8d99df1c2e9b3693d3eab Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Tue, 4 Jul 2023 16:50:52 +0500 Subject: [PATCH] web: force update token if email is already confirmed (#2879) --- packages/core/api/sync/index.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/core/api/sync/index.js b/packages/core/api/sync/index.js index a7ddbcdfa..b1cbe4a2a 100644 --- a/packages/core/api/sync/index.js +++ b/packages/core/api/sync/index.js @@ -65,6 +65,7 @@ export default class SyncManager { */ constructor(db) { this.sync = new Sync(db); + this._db = db; } async start(full, force) { @@ -76,6 +77,19 @@ export default class SyncManager { var isHubException = e.message.includes("HubException:"); if (isHubException) { var actualError = /HubException: (.*)/gm.exec(e.message); + + // NOTE: sometimes there's the case where the user has already + // confirmed their email but the server still thinks that it + // isn't confirmed. This check is added to trigger a force + // update of the access token. + if ( + actualError.includes("Please confirm your email ") && + (await this._db.user.getUser()).isEmailConfirmed + ) { + await this._db.user.tokenManager._refreshToken(true); + return false; + } + if (actualError.length > 1) throw new Error(actualError[1]); } throw e;