Skip to content

Commit 115b9db

Browse files
authored
Merge pull request #854 from bcgov/development
Dev to test
2 parents 8cf607d + a0c9894 commit 115b9db

File tree

7 files changed

+55
-19
lines changed

7 files changed

+55
-19
lines changed

auth-web/package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

auth-web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"moment": "^2.24.0",
2222
"regenerator-runtime": "^0.13.3",
2323
"register-service-worker": "^1.6.2",
24-
"sbc-common-components": "^2.1.37",
24+
"sbc-common-components": "^2.1.38",
2525
"vue": "^2.6.11",
2626
"vue-i18n": "^8.0.0",
2727
"vue-property-decorator": "^8.3.0",

auth-web/src/App.vue

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { Member, MembershipStatus, Organization } from '@/models/Organization'
3838
import { mapActions, mapGetters, mapMutations, mapState } from 'vuex'
3939
import { AccountSettings } from '@/models/account-settings'
4040
import BusinessModule from '@/store/modules/business'
41+
import CommonUtils from '@/util/common-util'
4142
import ConfigHelper from '@/util/config-helper'
4243
import { Event } from '@/models/event'
4344
import { EventBus } from '@/event-bus'
@@ -102,12 +103,6 @@ export default class App extends Mixins(NextPageMixin) {
102103
header: SbcHeader
103104
}
104105
105-
get signingIn (): boolean {
106-
return this.$route.name === 'signin' ||
107-
this.$route.name === 'signin-redirect' ||
108-
this.$route.name === 'signin-redirect-full'
109-
}
110-
111106
get showNavigationBar (): boolean {
112107
return this.$route.meta.showNavBar
113108
}
@@ -158,9 +153,17 @@ export default class App extends Mixins(NextPageMixin) {
158153
}
159154
}
160155
156+
private async created () {
157+
// If session is synced, then sync user details
158+
if (ConfigHelper.getFromSession(SessionStorageKeys.SessionSynced) === 'true' && !CommonUtils.isSigningIn() && !CommonUtils.isSigningOut()) {
159+
this.loadUserInfo()
160+
await this.syncUser()
161+
this.setupNavigationBar()
162+
this.$store.commit('loadComplete')
163+
}
164+
}
165+
161166
private async mounted (): Promise<void> {
162-
// set keycloak config file's location to the sbc-common-components
163-
await KeyCloakService.setKeycloakConfigUrl(`${process.env.VUE_APP_PATH}config/kc/keycloak.json`)
164167
this.showLoading = false
165168
166169
EventBus.$on('show-toast', (eventInfo: Event) => {
@@ -193,12 +196,11 @@ export default class App extends Mixins(NextPageMixin) {
193196
private async setup () {
194197
// Header added modules to store so can access mapped actions now
195198
if (this.$store.getters['auth/isAuthenticated']) {
196-
this.loadUserInfo()
197-
await this.syncUser()
198-
this.setupNavigationBar()
199199
try {
200-
await this.tokenService.init(this.$store)
201-
this.tokenService.scheduleRefreshTimer()
200+
this.initTokenService()
201+
this.loadUserInfo()
202+
await this.syncUser()
203+
this.setupNavigationBar()
202204
} catch (e) {
203205
// eslint-disable-next-line no-console
204206
console.log('Could not initialize token refresher: ' + e)
@@ -210,6 +212,11 @@ export default class App extends Mixins(NextPageMixin) {
210212
}
211213
this.$store.commit('loadComplete')
212214
}
215+
216+
private async initTokenService () {
217+
await this.tokenService.init(this.$store)
218+
this.tokenService.scheduleRefreshTimer()
219+
}
213220
}
214221
215222
</script>

auth-web/src/components/auth/mixins/NextPageMixin.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ export default class NextPageMixin extends Vue {
130130
131131
protected async syncUser () {
132132
// eslint-disable-next-line no-console
133-
this.setCurrentAccountSettings(this.getAccountFromSession())
134133
await this.syncUserProfile()
134+
this.setCurrentAccountSettings(this.getAccountFromSession())
135135
if (this.currentAccountSettings) {
136136
await this.syncMembership(this.currentAccountSettings.id)
137137
// await this.syncOrganization(this.currentAccountSettings.id)

auth-web/src/main.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import '@mdi/font/css/materialdesignicons.min.css' // icon library (https://mate
33
import 'regenerator-runtime/runtime' // to use transpiled generator functions
44
import './registerServiceWorker'
55
import App from './App.vue'
6+
import CommonUtils from '@/util/common-util'
67
import ConfigHelper from '@/util/config-helper'
8+
import KeyCloakService from 'sbc-common-components/src/services/keycloak.services'
79
import LaunchDarklyService from 'sbc-common-components/src/services/launchdarkly.services'
810
import TokenService from 'sbc-common-components/src/services/token.services'
911
import Vue from 'vue'
@@ -24,9 +26,26 @@ Vue.prototype.$tokenService = new TokenService()
2426
ConfigHelper.saveConfigToSessionStorage().then(async (data) => {
2527
// Initializing Launch Darkly services
2628
await LaunchDarklyService.init(ConfigHelper.getValue('LAUNCH_DARKLY_ENV_KEY'))
29+
await syncSession()
2730
renderVue()
2831
}
2932
)
33+
34+
async function syncSession () {
35+
await KeyCloakService.setKeycloakConfigUrl(`${process.env.VUE_APP_PATH}config/kc/keycloak.json`)
36+
37+
// Initialize token service which will do a check-sso to initiate session
38+
if (!CommonUtils.isSigningIn() && !CommonUtils.isSigningOut()) {
39+
await Vue.prototype.$tokenService.init(null).then(() =>
40+
Vue.prototype.$tokenService.scheduleRefreshTimer()
41+
).catch(err => {
42+
if (err.message !== 'NOT_AUTHENTICATED') {
43+
throw err
44+
}
45+
})
46+
}
47+
}
48+
3049
function renderVue () {
3150
new Vue({
3251
router,

auth-web/src/util/common-util.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,13 @@ export default class CommonUtils {
8989
}, 200)
9090
}
9191
}
92+
93+
static isSigningIn ():boolean {
94+
const path = window.location.pathname
95+
return path.includes('/signin') || path.includes('/signin-redirect') || path.includes('/signin-redirect-full')
96+
}
97+
static isSigningOut ():boolean {
98+
const path = window.location.pathname
99+
return path.includes('/signout')
100+
}
92101
}

auth-web/src/util/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ export enum SessionStorageKeys {
77
UserAccountType = 'USER_ACCOUNT_TYPE',
88
CurrentAccount = 'CURRENT_ACCOUNT',
99
LaunchDarklyFlags = 'LD_FLAGS',
10-
ExtraProvincialUser = 'EXTRAPROVINCIAL_USER'
10+
ExtraProvincialUser = 'EXTRAPROVINCIAL_USER',
11+
SessionSynced = 'SESSION_SYNCED'
1112
}
1213

1314
export enum Role {

0 commit comments

Comments
 (0)