Defer more auth logic to snjs

This commit is contained in:
Mo Bitar
2020-02-12 00:26:08 -06:00
parent d91d141417
commit 0fcfd98e5d
5 changed files with 239 additions and 341 deletions

View File

@@ -17,7 +17,6 @@ export class PureCtrl {
this.addAppStateObserver();
this.addAppEventObserver();
$scope.$on('$destroy', () => {
console.log("On destroy", this);
this.unsubApp();
this.unsubState();
});

View File

@@ -88,6 +88,7 @@ class AccountMenuCtrl extends PureCtrl {
close() {
this.$timeout(() => {
console.log(" : AccountMenuCtrl -> close -> timeout");
this.props.closeFunction()();
});
}
@@ -190,7 +191,8 @@ class AccountMenuCtrl extends PureCtrl {
});
const hasError = !response || response.error;
if (!hasError) {
await this.onAuthSuccess();
await this.setFormDataState({ authenticating: false });
this.close();
return;
}
await this.setFormDataState({
@@ -217,7 +219,7 @@ class AccountMenuCtrl extends PureCtrl {
}
}
await this.setFormDataState({
authenticating: false,
authenticating: false
});
}
@@ -254,8 +256,8 @@ class AccountMenuCtrl extends PureCtrl {
text: error.message
});
} else {
await this.onAuthSuccess();
this.application.sync();
await this.setFormDataState({ authenticating: false });
this.close();
}
}
@@ -273,17 +275,6 @@ class AccountMenuCtrl extends PureCtrl {
}
}
async onAuthSuccess() {
if (this.state.formData.mergeLocal) {
this.$rootScope.$broadcast('major-data-change');
await this.rewriteDatabase({ alternateUuids: true });
}
await this.setFormDataState({
authenticating: false
});
this.close();
}
openPasswordWizard(type) {
this.close();
this.godService.presentPasswordWizard(type);
@@ -309,17 +300,6 @@ class AccountMenuCtrl extends PureCtrl {
}
}
/**
* Allows IndexedDB unencrypted logs to be deleted
* `clearAllPayloads` will remove data from backing store,
* but not from working memory See:
* https://github.com/standardnotes/desktop/issues/131
*/
async rewriteDatabase({ alternateUuids } = {}) {
await this.application.clearDatabase();
await this.application.markAllItemsAsNeedingSync({ alternateUuids });
}
destroyLocalData() {
this.application.alertManager.confirm({
text: STRING_SIGN_OUT_CONFIRMATION,
@@ -503,10 +483,6 @@ class AccountMenuCtrl extends PureCtrl {
confirmPasscode: null,
showPasscodeForm: false
});
if (isNullOrUndefined(await this.application.getUser())) {
this.$rootScope.$broadcast('major-data-change');
this.rewriteDatabase();
}
});
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2
package-lock.json generated
View File

@@ -14961,6 +14961,8 @@
},
"sncrypto": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/sncrypto/-/sncrypto-1.0.0.tgz",
"integrity": "sha512-qCBIm7rzPpaIv1GQ0T5R7zDcHwLdYfCIpdIOrZP3PQlXhAb2h36ypaRfLC5stOQTCf3xtOU7o4Ht8pH5S+QfPw==",
"dependencies": {
"@babel/cli": {
"version": "7.7.5",