diff --git a/src/app/boot/app_controller.nim b/src/app/boot/app_controller.nim index b4a5d5a5e3..097fec965e 100644 --- a/src/app/boot/app_controller.nim +++ b/src/app/boot/app_controller.nim @@ -103,6 +103,7 @@ proc buildAndRegisterUserProfile(self: AppController) # Startup Module Delegate Interface proc startupDidLoad*(self: AppController) proc userLoggedIn*(self: AppController) +proc logout*(self: AppController) proc storeKeyPairForNewKeycardUser*(self: AppController) # Main Module Delegate Interface @@ -369,6 +370,9 @@ proc userLoggedIn*(self: AppController) = if not self.startupModule.isNil: self.startupModule.delete +proc logout*(self: AppController) = + self.generalService.logout() + proc buildAndRegisterLocalAccountSensitiveSettings(self: AppController) = var pubKey = self.settingsService.getPublicKey() singletonInstance.localAccountSensitiveSettings.setFileName(pubKey) diff --git a/src/app/modules/startup/io_interface.nim b/src/app/modules/startup/io_interface.nim index e03bb9ee56..ed93ae61df 100644 --- a/src/app/modules/startup/io_interface.nim +++ b/src/app/modules/startup/io_interface.nim @@ -28,6 +28,9 @@ method moveToLoadingAppState*(self: AccessInterface) {.base.} = method moveToAppState*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") +method moveToStartupState*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") + method onBackActionClicked*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/startup/module.nim b/src/app/modules/startup/module.nim index bf1f8416ee..9f49c83e19 100644 --- a/src/app/modules/startup/module.nim +++ b/src/app/modules/startup/module.nim @@ -118,6 +118,9 @@ method moveToLoadingAppState*[T](self: Module[T]) = method moveToAppState*[T](self: Module[T]) = self.view.setAppState(AppState.MainAppState) +method moveToStartupState*[T](self: Module[T]) = + self.view.setAppState(AppState.StartupState) + method startUpUIRaised*[T](self: Module[T]) = self.view.startUpUIRaised() @@ -284,7 +287,16 @@ method onNodeLogin*[T](self: Module[T], error: string) = quit() # quit the app if error.len == 0: - self.delegate.userLoggedIn() + try: + self.delegate.userLoggedIn() + except Exception as e: + let errDescription = e.msg + error "error: ", errDescription + self.delegate.logout() + self.moveToStartupState() + self.emitAccountLoginError(errDescription) + return + if currStateObj.flowType() != FlowType.AppLogin: self.controller.storeIdentityImage() self.controller.cleanTmpData() diff --git a/src/app_service/service/general/service.nim b/src/app_service/service/general/service.nim index 4eef74ef4d..ad49027fb3 100644 --- a/src/app_service/service/general/service.nim +++ b/src/app_service/service/general/service.nim @@ -23,12 +23,10 @@ proc init*(self: Service) = createDir(app_constants.ROOTKEYSTOREDIR) proc startMessenger*(self: Service) = - try: - discard status_general.startMessenger() - except Exception as e: - let errDesription = e.msg - error "error: ", errDesription - return + discard status_general.startMessenger() + +proc logout*(self: Service) = + discard status_general.logout() proc getPasswordStrengthScore*(self: Service, password, userName: string): int = try: diff --git a/src/backend/general.nim b/src/backend/general.nim index c5e0f86758..310262d753 100644 --- a/src/backend/general.nim +++ b/src/backend/general.nim @@ -22,6 +22,14 @@ proc startMessenger*(): RpcResponse[JsonNode] {.raises: [Exception].} = let payload = %* [] result = core.callPrivateRPC("startMessenger".prefix, payload) +proc logout*(): RpcResponse[JsonNode] {.raises: [Exception].} = + try: + let response = status_go.logout() + result.result = Json.decode(response, JsonNode) + except RpcException as e: + error "error logging out", methodName = "logout", exception=e.msg + raise newException(RpcException, e.msg) + proc generateSymKeyFromPassword*(password: string): RpcResponse[JsonNode] {.raises: [Exception].} = let payload = %* [password] result = core.callPrivateRPC("waku_generateSymKeyFromPassword", payload)