From c24f9ff1a13cb5b439779347c8db9b85d3c787c4 Mon Sep 17 00:00:00 2001 From: Zouheir Layine <58786497+zlayine@users.noreply.github.com> Date: Fri, 29 Sep 2023 17:44:58 +0300 Subject: [PATCH] Login fix (#35) --- resources/js/components/pages/Settings.vue | 205 +++++++++++---------- resources/js/store/index.ts | 5 +- 2 files changed, 113 insertions(+), 97 deletions(-) diff --git a/resources/js/components/pages/Settings.vue b/resources/js/components/pages/Settings.vue index 48fa5b1..ff38913 100644 --- a/resources/js/components/pages/Settings.vue +++ b/resources/js/components/pages/Settings.vue @@ -1,105 +1,111 @@ @@ -118,6 +124,7 @@ import CopyTextIcon from '../CopyTextIcon.vue'; import { PencilIcon } from '@heroicons/vue/20/solid'; import { AuthApi } from '~/api/auth'; import { addressToPublicKey, isValidAddress, publicKeyToAddress } from '~/util/address'; +import LoadingCircle from '../LoadingCircle.vue'; const router = useRouter(); const appStore = useAppStore(); @@ -127,6 +134,7 @@ const tokenName = ref(); const walletAccount = ref(publicKeyToAddress(appStore.user?.account)); const enableTokenCreate = ref(false); const enableAccountModify = ref(false); +const loading = ref(true); const tokens = computed(() => appStore.user?.apiTokens); @@ -221,9 +229,18 @@ watch( walletAccount.value = publicKeyToAddress(appStore.user?.account); } - if (!appStore.user.apiTokens.length) { + if (!appStore.user?.apiTokens.length) { enableTokenCreate.value = true; } } ); + +watch( + () => appStore.user, + (userVal) => { + if (userVal) { + loading.value = false; + } + } +); diff --git a/resources/js/store/index.ts b/resources/js/store/index.ts index 2242e21..501f93e 100644 --- a/resources/js/store/index.ts +++ b/resources/js/store/index.ts @@ -122,7 +122,7 @@ export const useAppStore = defineStore('app', { this.config.channel = appConfig.channel; } - if (window.bootstrap.daemon) { + if (window.bootstrap?.daemon) { this.config.daemon = window.bootstrap.daemon; } }, @@ -164,7 +164,6 @@ export const useAppStore = defineStore('app', { return true; }, async login(email: string, password: string) { - this.loggedIn = true; const res = await AuthApi.login(email, password); if (!res.data.Login) throw [{ field: 'Login error', message: 'Invalid credentials' }]; @@ -173,12 +172,12 @@ export const useAppStore = defineStore('app', { await this.logout(); throw [{ field: 'Login error', message: 'Please verify your email address' }]; } - this.loggedIn = res.data.Login; return res.data.Login; }, async logout() { + this.loggedIn = false; await AuthApi.logout(); this.clearLogin(); },