Skip to content

Commit

Permalink
Merge pull request #98 from ymaheshwari1/user/#181
Browse files Browse the repository at this point in the history
Implemented: support to not display login alert in any case and login into the app with the incoming credentials
  • Loading branch information
ymaheshwari1 authored Apr 1, 2024
2 parents 8c63487 + 61e64dc commit 8bc1ec6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 46 deletions.
3 changes: 0 additions & 3 deletions src/locales/en.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"Already active session": "Already active session",
"Failed to fetch user-profile, please try again": "Failed to fetch user-profile, please try again",
"Launch Pad": "Launch Pad",
"Login": "Login",
Expand All @@ -11,9 +10,7 @@
"Please fill in the OMS": "Please fill in the OMS",
"Please fill in the user details": "Please fill in the user details",
"Processing": "Processing",
"Resume": "Resume",
"Something went wrong while login. Please contact administrator.": "Something went wrong while login. Please contact administrator.",
"Sorry, your username or password is incorrect. Please try again.": "Sorry, your username or password is incorrect. Please try again.",
"There is an already active session on for. Do you want to resume it, or would you prefer to log in again?": "There is an already active session on {oms} for {partyName}. Do you want to resume it, or would you prefer to log in again?",
"Username": "Username"
}
52 changes: 9 additions & 43 deletions src/views/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@

<script lang="ts">
import {
alertController,
IonButton,
IonChip,
IonContent,
Expand Down Expand Up @@ -116,9 +115,8 @@ 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) {
// if a session is already active, present alert
if (this.authStore.isAuthenticated) {
await this.confirmActvSessnLoginOnRedrct(true)
if(this.authStore.getRedirectUrl) {
window.location.href = `${this.authStore.getRedirectUrl}?oms=${this.$route.query?.oms}&token=${this.$route.query?.token}`
} else {
await this.basicLogin()
this.dismissLoader();
Expand Down Expand Up @@ -157,9 +155,13 @@ export default defineComponent({
this.authStore.setRedirectUrl(this.$route.query.redirectUrl as string)
}
// if a session is already active, present alert
if (this.authStore.isAuthenticated && this.$route.query?.redirectUrl) {
await this.confirmActvSessnLoginOnRedrct()
// if a session is already active, login directly in the app
if (this.authStore.isAuthenticated) {
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.instanceUrl = this.authStore.oms;
Expand Down Expand Up @@ -285,42 +287,6 @@ export default defineComponent({
console.error("error: ", error);

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

View workflow job for this annotation

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

Unexpected console statement

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

View workflow job for this annotation

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

Unexpected console statement

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

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / build_and_deploy

Unexpected console statement
}
this.router.replace('/')
},
// 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({
translucent: true,
backdropDismiss: false,
header: translate('Already active session'),
message: translate(`There is an already active session on for. Do you want to resume it, or would you prefer to log in again?`, { partyName: this.authStore.current.partyName, oms: this.authStore.getOMS }),
buttons: [{
text: translate('Resume'),
handler: () => {
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()
this.authStore.setRedirectUrl(redirectUrl)
this.isConfirmingForActiveSession = false;
if(redirect) {
this.basicLogin()
return;
}
}
}]
});
return alert.present();
}
},
setup () {
Expand Down

0 comments on commit 8bc1ec6

Please sign in to comment.