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

Improved: flow for accessing login route and implemented launchpad logout on app logout #33

Merged
merged 2 commits into from
Aug 3, 2023
Merged
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
10 changes: 10 additions & 0 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ import { createRouter, createWebHistory } from '@ionic/vue-router';
import { RouteRecordRaw } from 'vue-router';
import Home from '@/views/Home.vue';
import Login from '@/views/Login.vue';
import { useAuthStore } from "@/store/auth";

const loginGuard = (to: any, from: any, next: any) => {
const authStore = useAuthStore()
if (authStore.isAuthenticated && !to.query?.redirectUrl) {
next('/home')
}
next();
};

const routes: Array<RouteRecordRaw> = [
{
Expand All @@ -17,6 +26,7 @@ const routes: Array<RouteRecordRaw> = [
path: '/login',
name: 'Login',
component: Login,
beforeEnter: loginGuard
}
];

Expand Down
47 changes: 26 additions & 21 deletions src/views/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
<ion-icon slot="end" :icon="arrowForwardOutline" />
</ion-button>
</div>
<ion-fab @click="router.push('/')" vertical="bottom" horizontal="end" slot="fixed">
<ion-fab-button color="medium">
<ion-icon :icon="gridOutline" />
</ion-fab-button>
</ion-fab>
</section>

<section v-else>
Expand Down Expand Up @@ -54,6 +59,8 @@
IonButton,
IonChip,
IonContent,
IonFab,
IonFabButton,
IonIcon,
IonInput,
IonItem,
Expand All @@ -65,7 +72,7 @@
import { useRouter } from "vue-router";
import { useAuthStore } from "@/store/auth";
import Logo from '@/components/Logo.vue';
import { arrowForwardOutline } from 'ionicons/icons'
import { arrowForwardOutline, gridOutline } from 'ionicons/icons'
import { UserService } from "@/services/UserService";
import { translate } from "@/i18n";
import { showToast } from "@/util";
Expand All @@ -77,6 +84,8 @@
IonButton,
IonChip,
IonContent,
IonFab,
IonFabButton,
IonIcon,
IonInput,
IonItem,
Expand Down Expand Up @@ -112,8 +121,13 @@
return
}

// show OMS input field if query has OMS or if both query and state does not have OMS
if (this.$route.query?.oms || this.authStore.getOMS) {
// logout from Launchpad if logged out from the app
if (this.$route.query?.isLoggedOut === 'true') {
this.authStore.logout()
}

// show OMS input field if query or state does not have OMS
if (this.$route.query?.oms || !this.authStore.getOMS) {
this.showOmsInput = true
}

Expand All @@ -127,9 +141,11 @@
this.authStore.setRedirectUrl(this.$route.query.redirectUrl as string)
}

// if a session is already active, present alerts based on redirectUrl being sent
await this.handleActiveSessionLogin()

// if a session is already active, present alert
if (this.authStore.isAuthenticated && this.$route.query?.redirectUrl) {
await this.confirmActvSessnLoginOnRedrct()
}

this.instanceUrl = this.authStore.oms;
if (this.authStore.oms) {
// If the current URL is available in alias show it for consistency
Expand All @@ -142,7 +158,6 @@
}
this.dismissLoader();
this.hideBackground = false

},
async presentLoader(message: string) {
if (!this.loader) {
Expand Down Expand Up @@ -195,7 +210,7 @@
}
}
} catch (error) {
console.error(error)

Check warning on line 213 in src/views/Login.vue

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (14.x)

Unexpected console statement

Check warning on line 213 in src/views/Login.vue

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (16.x)

Unexpected console statement
// Fallback TODO Remove this
this.toggleOmsInput()
}
Expand All @@ -218,7 +233,7 @@
this.router.push('/')
}
} catch (error) {
console.error(error)

Check warning on line 236 in src/views/Login.vue

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (14.x)

Unexpected console statement

Check warning on line 236 in src/views/Login.vue

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (16.x)

Unexpected console statement
}
},
async samlLogin() {
Expand All @@ -231,17 +246,10 @@
this.router.push('/')
}
} catch (error) {
console.error(error)

Check warning on line 249 in src/views/Login.vue

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (14.x)

Unexpected console statement

Check warning on line 249 in src/views/Login.vue

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (16.x)

Unexpected console statement
}
},
async handleActiveSessionLogin() {
if (this.authStore.isAuthenticated) {
// optional true parameter for redirectUrl case
if (this.$route.query?.redirectUrl) await this.confirmActiveSessionLogin(true)
else await this.confirmActiveSessionLogin()
}
},
async confirmActiveSessionLogin(redirect?: boolean) {
async confirmActvSessnLoginOnRedrct() {
this.isConfirmingForActiveSession = true
const alert = await alertController
.create({
Expand All @@ -252,19 +260,15 @@
buttons: [{
text: translate('Continue'),
handler: () => {
redirect
? window.location.href = `${this.authStore.getRedirectUrl}?oms=${this.authStore.oms}&token=${this.authStore.token.value}&expirationTime=${this.authStore.token.expiration}`
: this.router.push('/')
window.location.href = `${this.authStore.getRedirectUrl}?oms=${this.authStore.oms}&token=${this.authStore.token.value}&expirationTime=${this.authStore.token.expiration}`
this.isConfirmingForActiveSession = false;
}
}, {
text: translate('Re-login'),
handler: async () => {
const redirectUrl = this.authStore.getRedirectUrl
await this.authStore.logout()
// re-set the redirectUrl if redirect flow was called
// as it got cleared on logout
if (redirect) this.authStore.setRedirectUrl(redirectUrl)
this.authStore.setRedirectUrl(redirectUrl)
this.isConfirmingForActiveSession = false;
}
}]
Expand All @@ -278,6 +282,7 @@
return {
arrowForwardOutline,
authStore,
gridOutline,
router
};
}
Expand Down
Loading