From b4cd78982b92a5a03606d20a6db083f1e6bbd44c Mon Sep 17 00:00:00 2001 From: k2maan Date: Sun, 6 Aug 2023 22:11:40 +0530 Subject: [PATCH 1/7] Improved: implemented code to rehydrate state on login click to avoid multiple logins in case of multiple tabs and removed code to open tabs in new window --- src/views/Home.vue | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/views/Home.vue b/src/views/Home.vue index b4a637f..faee2fd 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -16,7 +16,7 @@ {{ $t('Logout') }} - + {{ $t('Login') }} @@ -25,17 +25,17 @@

{{ category }}

- +
{{ app.name }} - + - + @@ -86,6 +86,17 @@ export default defineComponent({ IonLabel, IonPage }, + methods: { + login() { + // hydrate (pinia-plugin-persistedstate) will sync the app state with the + // localStorage state for avoiding the case when two launchpad tabs are opened + // and the user logs in through one and tries to login again from the next tab + // $hydate will resync the state and hence, update the app UI + this.authStore.$hydrate({ runHooks: false }) + if (this.authStore.isAuthenticated) return + this.router.push('/login') + }, + }, setup() { const authStore = useAuthStore(); const router = useRouter(); From 0ae08362008bf544a9764e5cc63ee0717d9ccc67 Mon Sep 17 00:00:00 2001 From: k2maan Date: Mon, 7 Aug 2023 15:57:46 +0530 Subject: [PATCH 2/7] Implemented: code to check auth before launching the app --- src/views/Home.vue | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/views/Home.vue b/src/views/Home.vue index faee2fd..f17d347 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -25,17 +25,17 @@

{{ category }}

- +
{{ app.name }} - + - + @@ -71,6 +71,7 @@ import { } from 'ionicons/icons'; import { useAuthStore } from '@/store/auth'; import { useRouter } from "vue-router"; +import { DateTime } from "luxon"; export default defineComponent({ name: 'Home', @@ -96,6 +97,16 @@ export default defineComponent({ if (this.authStore.isAuthenticated) return this.router.push('/login') }, + launchApp(handle: string, env?: string) { + // checking token expiration directly as pinia getter is not updating the state + if (this.authStore.isAuthenticated) { + const isTokenExpired = +(this.authStore.token.expiration as any) < DateTime.now().toMillis(); + isTokenExpired && this.authStore.logout() + } + return env?.length + ? window.location.href = this.scheme + handle + env + this.domain + (this.authStore.isAuthenticated ? `/login?oms=${this.authStore.getOMS}&token=${this.authStore.token.value}&expirationTime=${this.authStore.token.expiration}` : '') + : window.location.href = this.scheme + handle + this.domain + (this.authStore.isAuthenticated ? `/login?oms=${this.authStore.getOMS}&token=${this.authStore.token.value}&expirationTime=${this.authStore.token.expiration}` : '') + } }, setup() { const authStore = useAuthStore(); From 4efaebaba3fe4d4c1709b7921b14a2d7677e32ac Mon Sep 17 00:00:00 2001 From: k2maan Date: Mon, 7 Aug 2023 19:08:29 +0530 Subject: [PATCH 3/7] Improved: logic for adding env handle in the link --- src/views/Home.vue | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/views/Home.vue b/src/views/Home.vue index f17d347..8cccba1 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -103,9 +103,7 @@ export default defineComponent({ const isTokenExpired = +(this.authStore.token.expiration as any) < DateTime.now().toMillis(); isTokenExpired && this.authStore.logout() } - return env?.length - ? window.location.href = this.scheme + handle + env + this.domain + (this.authStore.isAuthenticated ? `/login?oms=${this.authStore.getOMS}&token=${this.authStore.token.value}&expirationTime=${this.authStore.token.expiration}` : '') - : window.location.href = this.scheme + handle + this.domain + (this.authStore.isAuthenticated ? `/login?oms=${this.authStore.getOMS}&token=${this.authStore.token.value}&expirationTime=${this.authStore.token.expiration}` : '') + return window.location.href = this.scheme + handle + (env?.length ? env : + '') + this.domain + (this.authStore.isAuthenticated ? `/login?oms=${this.authStore.getOMS}&token=${this.authStore.token.value}&expirationTime=${this.authStore.token.expiration}` : '') } }, setup() { From bd6f0692c160a25268239e45bd9c5ddd71f43cc2 Mon Sep 17 00:00:00 2001 From: k2maan Date: Fri, 1 Sep 2023 18:05:13 +0530 Subject: [PATCH 4/7] Reverted: code to check login state before launching app --- src/views/Home.vue | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/views/Home.vue b/src/views/Home.vue index 8cccba1..f5e5066 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -99,10 +99,6 @@ export default defineComponent({ }, launchApp(handle: string, env?: string) { // checking token expiration directly as pinia getter is not updating the state - if (this.authStore.isAuthenticated) { - const isTokenExpired = +(this.authStore.token.expiration as any) < DateTime.now().toMillis(); - isTokenExpired && this.authStore.logout() - } return window.location.href = this.scheme + handle + (env?.length ? env : + '') + this.domain + (this.authStore.isAuthenticated ? `/login?oms=${this.authStore.getOMS}&token=${this.authStore.token.value}&expirationTime=${this.authStore.token.expiration}` : '') } }, From 9e328144a818b4d64cff66010a6928b8cf2e0987 Mon Sep 17 00:00:00 2001 From: k2maan Date: Mon, 4 Sep 2023 10:34:43 +0530 Subject: [PATCH 5/7] Removed: launchApp function on onClick and used href --- src/views/Home.vue | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/views/Home.vue b/src/views/Home.vue index f5e5066..92868e8 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -25,17 +25,17 @@

{{ category }}

- +
{{ app.name }} - + - + @@ -96,10 +96,6 @@ export default defineComponent({ this.authStore.$hydrate({ runHooks: false }) if (this.authStore.isAuthenticated) return this.router.push('/login') - }, - launchApp(handle: string, env?: string) { - // checking token expiration directly as pinia getter is not updating the state - return window.location.href = this.scheme + handle + (env?.length ? env : + '') + this.domain + (this.authStore.isAuthenticated ? `/login?oms=${this.authStore.getOMS}&token=${this.authStore.token.value}&expirationTime=${this.authStore.token.expiration}` : '') } }, setup() { From 535e12be62f78237acf2695fcbd9af099fb2b4c2 Mon Sep 17 00:00:00 2001 From: k2maan Date: Mon, 4 Sep 2023 10:36:49 +0530 Subject: [PATCH 6/7] Improved: unused luxon import removed --- src/views/Home.vue | 1 - 1 file changed, 1 deletion(-) diff --git a/src/views/Home.vue b/src/views/Home.vue index 92868e8..1c2c30e 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -71,7 +71,6 @@ import { } from 'ionicons/icons'; import { useAuthStore } from '@/store/auth'; import { useRouter } from "vue-router"; -import { DateTime } from "luxon"; export default defineComponent({ name: 'Home', From 98511a5b24eea780c21d038db79058e51900ed09 Mon Sep 17 00:00:00 2001 From: k2maan Date: Tue, 10 Oct 2023 18:03:32 +0530 Subject: [PATCH 7/7] Improved: synced app state on logout --- src/store/auth.ts | 2 +- src/views/Home.vue | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/store/auth.ts b/src/store/auth.ts index 33564a9..c15cf61 100644 --- a/src/store/auth.ts +++ b/src/store/auth.ts @@ -22,7 +22,7 @@ export const useAuthStore = defineStore('authStore', { const currTime = DateTime.now().toMillis(); isTokenExpired = state.token.expiration < currTime; } - return state.token.value && !isTokenExpired; + return !!(state.token.value && !isTokenExpired); }, getOMS: (state) => state.oms, getBaseUrl: (state) => { diff --git a/src/views/Home.vue b/src/views/Home.vue index 1c2c30e..8c46cfe 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -14,7 +14,7 @@

{{ authStore.getOMS }}

{{ authStore.current?.partyName ? authStore.current?.partyName : authStore.current.userLoginId }}

- {{ $t('Logout') }} + {{ $t('Logout') }} @@ -65,9 +65,9 @@ import { defineComponent, ref } from 'vue'; import { codeWorkingOutline, lockClosedOutline, + personCircleOutline, rocketOutline, - shieldHalfOutline, - personCircleOutline + shieldHalfOutline } from 'ionicons/icons'; import { useAuthStore } from '@/store/auth'; import { useRouter } from "vue-router"; @@ -93,8 +93,17 @@ export default defineComponent({ // and the user logs in through one and tries to login again from the next tab // $hydate will resync the state and hence, update the app UI this.authStore.$hydrate({ runHooks: false }) - if (this.authStore.isAuthenticated) return - this.router.push('/login') + // push to login only if user is not logged in (after state hydration) + if (!this.authStore.isAuthenticated) { + this.router.push('/login') + } + }, + async logout() { + this.authStore.$hydrate({ runHooks: false }) + // hydrate and logout only if user is logged in (authenticated) + if (this.authStore.isAuthenticated) { + await this.authStore.logout() + } } }, setup() { @@ -230,9 +239,6 @@ export default defineComponent({ object-fit: cover; } - .app-content { - } - ion-card { border-radius: 40px; transition: .4s cubic-bezier(0.59, 0.08, 0.05, 1.4);