From 2669a3e8adeeb20649bd2ed3e3f4e104b49dcc86 Mon Sep 17 00:00:00 2001 From: fyears Date: Tue, 30 Nov 2021 00:21:15 +0800 Subject: [PATCH] fix auth dropbox --- src/main.ts | 5 +++-- src/remoteForDropbox.ts | 19 +++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main.ts b/src/main.ts index ef545f8..c2553ec 100644 --- a/src/main.ts +++ b/src/main.ts @@ -338,11 +338,12 @@ export class DropboxAuthModal extends Modal { k.verifier, authCode ); + const self = this; setConfigBySuccessfullAuthInplace( this.plugin.settings.dropbox, - authRes + authRes, + () => self.plugin.saveSettings() ); - const self = this; const client = new RemoteClient( "dropbox", undefined, diff --git a/src/remoteForDropbox.ts b/src/remoteForDropbox.ts index becc801..9e5fbac 100644 --- a/src/remoteForDropbox.ts +++ b/src/remoteForDropbox.ts @@ -229,9 +229,10 @@ export const sendRefreshTokenReq = async ( return resp2; }; -export const setConfigBySuccessfullAuthInplace = ( +export const setConfigBySuccessfullAuthInplace = async ( config: DropboxConfig, - authRes: DropboxSuccessAuthRes + authRes: DropboxSuccessAuthRes, + saveUpdatedConfigFunc: () => Promise | undefined ) => { console.log("start updating local info of Dropbox token"); @@ -247,6 +248,10 @@ export const setConfigBySuccessfullAuthInplace = ( config.accountID = authRes.account_id; } + if (saveUpdatedConfigFunc !== undefined) { + await saveUpdatedConfigFunc(); + } + console.log("finish updating local info of Dropbox token"); }; @@ -269,7 +274,7 @@ export class WrappedDropboxClient { init = async () => { if ( this.dropboxConfig.accessToken === "" || - this.dropboxConfig.username === "" + this.dropboxConfig.refreshToken === "" ) { throw Error("The user has not manually auth yet."); } @@ -289,9 +294,11 @@ export class WrappedDropboxClient { this.dropboxConfig.refreshToken ); - setConfigBySuccessfullAuthInplace(this.dropboxConfig, resp); - await this.saveUpdatedConfigFunc(); - + setConfigBySuccessfullAuthInplace( + this.dropboxConfig, + resp, + this.saveUpdatedConfigFunc + ); this.dropbox = new Dropbox({ accessToken: this.dropboxConfig.accessToken, });