Skip to content

Commit

Permalink
Implemented: support to present alert when user is already logged-in
Browse files Browse the repository at this point in the history
  • Loading branch information
ymaheshwari1 committed Mar 8, 2024
1 parent 56872b2 commit dabcad7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useAuthStore } from "@/store/auth";

const loginGuard = (to: any, from: any, next: any) => {
const authStore = useAuthStore()
if (authStore.isAuthenticated && !to.query?.redirectUrl) {
if (authStore.isAuthenticated && !to.query?.redirectUrl && !to.query?.oms) {
next('/home')
}
next();
Expand Down
25 changes: 20 additions & 5 deletions src/views/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,14 @@ export default defineComponent({
// Run the basic login flow when oms and token both are found in query
if (this.$route.query?.oms && this.$route.query?.token) {
await this.basicLogin()
this.dismissLoader();
return;
// if a session is already active, present alert
if (this.authStore.isAuthenticated) {
await this.confirmActvSessnLoginOnRedrct(true)
} else {
await this.basicLogin()
this.dismissLoader();
return;
}
} else if (this.$route.query?.token) {
// SAML login handling as only token will be returned in the query when login through SAML
await this.samlLogin()
Expand Down Expand Up @@ -278,7 +283,8 @@ export default defineComponent({
}
this.router.push('/')
},
async confirmActvSessnLoginOnRedrct() {
// Pass redirect as true when you want to remove all the url params when user clicks on login
async confirmActvSessnLoginOnRedrct(redirect = false) {
this.isConfirmingForActiveSession = true
const alert = await alertController
.create({
Expand All @@ -289,14 +295,23 @@ export default defineComponent({
buttons: [{
text: translate('Resume'),
handler: () => {
window.location.href = `${this.authStore.getRedirectUrl}?oms=${this.authStore.oms}&token=${this.authStore.token.value}&expirationTime=${this.authStore.token.expiration}`
if(this.authStore.getRedirectUrl) {
window.location.href = `${this.authStore.getRedirectUrl}?oms=${this.authStore.oms}&token=${this.authStore.token.value}&expirationTime=${this.authStore.token.expiration}`
} else {
this.router.push('/')
}
this.isConfirmingForActiveSession = false;
}
}, {
text: translate('Login'),
handler: async () => {
const redirectUrl = this.authStore.getRedirectUrl
await this.authStore.logout()
if(redirect) {
this.router.push('/login')
}
this.authStore.setRedirectUrl(redirectUrl)
this.isConfirmingForActiveSession = false;
}
Expand Down

0 comments on commit dabcad7

Please sign in to comment.