diff --git a/app/frontend/src/common/authenticate.js b/app/frontend/src/common/authenticate.js index 9fce931d0..35f9cce99 100644 --- a/app/frontend/src/common/authenticate.js +++ b/app/frontend/src/common/authenticate.js @@ -129,7 +129,7 @@ export default { token, refreshToken, idToken } - ).success((result) => { + ).then((result) => { if (instance.authenticated) { // We may have been authenticated, but the token could be expired. instance.updateToken(60).success(() => { @@ -156,7 +156,7 @@ export default { store.commit('SET_KEYCLOAK', instance) resolve(instance) } - }).error((e) => { + }).catch((e) => { reject(e) }) } diff --git a/app/frontend/src/common/components/Auth.vue b/app/frontend/src/common/components/Auth.vue index 3423fd668..0b330f3ec 100644 --- a/app/frontend/src/common/components/Auth.vue +++ b/app/frontend/src/common/components/Auth.vue @@ -40,10 +40,8 @@ export default { keyCloakLogin () { this.keycloak.init() .then(() => { - console.log("Keycloak initialized successfully", this); return this.keycloak.login({ idpHint: this.config.sso_idp_hint }); }).then((authenticated) => { - console.log("keycloack login authenticated") if (authenticated) { ApiService.authHeader('JWT', this.keycloak.token) if (window.localStorage) { @@ -53,7 +51,6 @@ export default { } } }).catch((error) => { - console.error("Keycloak login failed", error); this.$store.commit(SET_ERROR, { error: 'Cannot contact SSO provider' }); }); }, @@ -72,7 +69,6 @@ export default { }, watch: { keycloak (kc) { - console.log("keycloack watch: ", kc) if (kc) { if (window._paq && this.authenticated) { window._paq.push(["setCustomVariable", 1, "userType", this.keycloak.tokenParsed.identity_provider]); diff --git a/app/frontend/src/common/components/Header.vue b/app/frontend/src/common/components/Header.vue index c66c41ff4..764174ff9 100644 --- a/app/frontend/src/common/components/Header.vue +++ b/app/frontend/src/common/components/Header.vue @@ -69,7 +69,6 @@ export default { computed: { ...mapGetters(['userRoles', 'config']), hasConfig () { - console.log("has config: ", Boolean(this.config)) return Boolean(this.config) }, getEnvironmentMessage () { diff --git a/app/frontend/src/common/store/config.js b/app/frontend/src/common/store/config.js index 456cbfc0a..b5c262bae 100644 --- a/app/frontend/src/common/store/config.js +++ b/app/frontend/src/common/store/config.js @@ -14,17 +14,15 @@ const config = { }, getters: { config (state) { - console.log("config: ", state) return state.config } }, actions: { - async [FETCH_CONFIG] ({ commit }, params) { + async [FETCH_CONFIG] ({ state, getters, commit }, params) { // We only fetch config if we don't have a copy cached if (getters.config === null) { try { const response = await ApiService.query('config', params) - console.log("config response", response) commit(SET_CONFIG, response.data) } catch (error) { console.log("Error: ", error) diff --git a/app/frontend/src/main.js b/app/frontend/src/main.js index 1e1c712d3..64356e56c 100644 --- a/app/frontend/src/main.js +++ b/app/frontend/src/main.js @@ -136,12 +136,12 @@ app.use(store); app.mixin({ methods: { - ...store.dispatch, + ...mapActions([FETCH_CONFIG]) }, created() { - // this.FETCH_CONFIG(); // Ensure FETCH_CONFIG is correctly defined in actions - // window._paq.push(["trackPageView"]); // Example of tracking pageview - }, + this.FETCH_CONFIG() + // window._paq.push(["trackPageView"]); + } }); app.mount('#app'); \ No newline at end of file diff --git a/app/frontend/src/router.js b/app/frontend/src/router.js index 438ddc508..946afc1dd 100644 --- a/app/frontend/src/router.js +++ b/app/frontend/src/router.js @@ -266,7 +266,9 @@ const router = createRouter({ }); const isAuthenticated = () => { - return router.app?.$keycloak?.authenticated ?? false; + if (!router?.app || !router?.app?.$keycloack) return false; + + return router.app.$keycloak; } const authenciateUser = (next) => { @@ -281,9 +283,22 @@ const authenciateUser = (next) => { }) } -router.beforeEach((to, from, next) => { - if (!isAuthenticated()) { - authenciateUser(next) +router.beforeEach(async (to, from, next) => { + if (!router?.app?.$keycloack) { + try { + const isAuthenticated = await authenticate.authenticate(store); + + console.log("isAuthenticated: ", isAuthenticated); + + if (keycloak?.authenticated) { + Sentry.setUser({ username: keycloak.tokenParsed.preferred_username }) + } + next() + } catch (error) { + console.log("Keycloak Authentication ERROR: ", error); + next() + } + } else { next() }