From e8dcae7a4467c90bfef8f5649a8914e8eb2c1b5f Mon Sep 17 00:00:00 2001 From: slavas490 Date: Mon, 11 Dec 2023 23:36:42 +0200 Subject: [PATCH] fix signup with metamask --- ui/core/src/views/RegisterRequest.vue | 44 +++++++++++++++++---------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/ui/core/src/views/RegisterRequest.vue b/ui/core/src/views/RegisterRequest.vue index e340a0fc0..ed3dc726c 100644 --- a/ui/core/src/views/RegisterRequest.vue +++ b/ui/core/src/views/RegisterRequest.vue @@ -147,36 +147,48 @@ export default { await window.ethereum.enable() await this.app.wallet.wallet.setupDefaultAccount() } catch (e) { - console.log(e) + this.app.deleteUserHasSession() this.walletErrorMessage = this.$t('Please grant access to MetaMask.') return } } else { + this.app.deleteUserHasSession() this.walletErrorMessage = this.$t('Please grant access to MetaMask.') return } + this.account = this.app.wallet.getCurrentAddress() + if (this.account === undefined) { + this.app.deleteUserHasSession() this.walletErrorMessage = this.$t('Please sign in to MetaMask.') return } + if (this.checkTermsAndConditions()) { - this.app.wallet.signMessage(this.challenge, this.account).then((signature) => { - axios.post('/api/login', { signature }).then((res) => { - this.challenge = '' - if (res.status >= 200 && res.status <= 299) { - window.location = res.data.location || '/admin/workflow' - } else { - this.walletErrorMessage = this.$t('Could not verify signature.') - } - }, (err) => { - this.challenge = '' - this.app.handleError(err) - this.walletErrorMessage = this.$t('Could not verify signature.') + this.app.wallet.signMessage(this.challenge, this.account) + .then((signature) => { + axios.post('/api/login', { signature }) + .then((res) => { + this.challenge = '' + + if (res.status >= 200 && res.status <= 299) { + this.app.initUserHasSession() + window.location = res.data.location || '/admin/workflow' + } else { + this.app.deleteUserHasSession() + this.walletErrorMessage = this.$t('Could not verify signature.') + } + }, (err) => { + this.challenge = '' + this.app.deleteUserHasSession() + this.app.handleError(err) + this.walletErrorMessage = this.$t('Could not verify signature.') + }) + }).catch(() => { + this.app.deleteUserHasSession() + this.walletErrorMessage = this.$t('Could not Sign Message.') }) - }).catch(() => { - this.walletErrorMessage = this.$t('Could not Sign Message.') - }) } } }