Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented: spinner inside the logout button(#60) #80

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions src/store/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export const useAuthStore = defineStore('authStore', {
value: '',
expiration: undefined
},
redirectUrl: ''
redirectUrl: '',
logOff:false
}),
getters: {
isAuthenticated: (state) => {
Expand All @@ -31,6 +32,7 @@ export const useAuthStore = defineStore('authStore', {
return baseURL.startsWith('http') ? baseURL : `https://${baseURL}.hotwax.io/api/`
},
getRedirectUrl: (state) => state.redirectUrl,
getLogOff:(state)=>state.logOff
},
actions: {
setOMS(oms: string) {
Expand Down Expand Up @@ -87,21 +89,21 @@ export const useAuthStore = defineStore('authStore', {
}
},
async logout(payload?: any) {
// Calling the logout api to flag the user as logged out, only when user is authorised
// if the user is already unauthorised then not calling the logout api as it returns 401 again that results in a loop, thus there is no need to call logout api if the user is unauthorised
if(!payload?.isUserUnauthorised) {
await logout();
}

// resetting the whole state except oms
// TODO Check why $patch failed to update current and use
this.current = {}
this.token = {
value: '',
expiration: undefined
this.logOff = true;
try{
if(!payload?.isAuthenticated) {
await logout()
}
this.current = {}
this.token = {
value:'',
expiration:undefined
}
this.redirectUrl = ''
updateToken('')
}finally{
this.logOff = false
}
this.redirectUrl = ''
updateToken('');
}
},
persist: true
Expand Down
20 changes: 11 additions & 9 deletions src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
<ion-label>
{{ authStore.current?.partyName ? authStore.current?.partyName : authStore.current.userLoginId }}
</ion-label>
<ion-button fill="outline" color="medium" slot="end" @click="authStore.logout()">
<ion-button fill="outline" color="medium" slot="end" @click="loggingout()">
<ion-spinner name="circular" v-if="authStore.getLogOff"></ion-spinner>
{{ $t('Logout') }}
</ion-button>
</ion-item>
Expand Down Expand Up @@ -73,7 +74,8 @@ import {
IonItem,
IonLabel,
IonList,
IonPage
IonPage,
IonSpinner
} from '@ionic/vue';
import { defineComponent, ref } from 'vue';
import {
Expand Down Expand Up @@ -102,7 +104,8 @@ export default defineComponent({
IonItem,
IonLabel,
IonList,
IonPage
IonPage,
IonSpinner
},
ionViewDidEnter() {
// clearing the redirect URL to break the login and redirection flow
Expand All @@ -121,12 +124,9 @@ export default defineComponent({
this.router.push('/login')
}
},
async logout() {
async loggingout() {
this.authStore.$hydrate({ runHooks: false })
// hydrate and logout only if user is logged in (authenticated)
if (this.authStore.isAuthenticated) {
await this.authStore.logout()
}
await this.authStore.logout();
}
},
setup() {
Expand Down Expand Up @@ -204,6 +204,7 @@ export default defineComponent({
const domain = ref('.hotwax.io')
const uatHandle = ref('-uat')
const devHandle = ref('-dev')
const logOff = ref(false)

return {
authStore,
Expand All @@ -220,7 +221,8 @@ export default defineComponent({
router,
scheme,
shieldHalfOutline,
uatHandle
uatHandle,
logOff
}
}
});
Expand Down