From f96923dbc692bf7ee25dad528b0c9eb8e45b932d Mon Sep 17 00:00:00 2001 From: NIK Date: Thu, 24 Oct 2024 20:10:35 +0800 Subject: [PATCH] fix: prevent autologin from crashing the app --- src/store/accounts/actions.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/store/accounts/actions.js b/src/store/accounts/actions.js index 8ec6a96b7..e3ade66c3 100644 --- a/src/store/accounts/actions.js +++ b/src/store/accounts/actions.js @@ -116,16 +116,20 @@ export const logout = async function ({ commit }) { } export const autoLogin = async function ({ dispatch }) { - if (typeof window.LightWalletChannel === 'object') { - return !dispatch('lightWalletLogin') - } - - const wallet = localStorage.getItem('autoLogin') - const idx = this.$ual.authenticators.findIndex(auth => auth.ualName === wallet) - if (idx !== -1) { - const authenticator = this.$ual.authenticators[idx] - await authenticator.init() - return !dispatch('loginWallet', { idx }) + try { + if (typeof window.LightWalletChannel === 'object') { + return !dispatch('lightWalletLogin') + } + const wallet = localStorage.getItem('autoLogin') + const idx = this.$ual.authenticators.findIndex(auth => auth.ualName === wallet) + if (idx !== -1) { + const authenticator = this.$ual.authenticators[idx] + await authenticator.init() + return !dispatch('loginWallet', { idx }) + } + } catch (err) { + console.log('autologin error - logging out.') + localStorage.clear() } return false }