diff --git a/src/store/index.js b/src/store/index.js index e2d18f63ece7b68bca60a6a7032e91c19a2827d2..301cffd9d86b624574b6ef23b3166d0278b62b63 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -54,7 +54,7 @@ export default new Vuex.Store({ SET_CONFIG(state, payload) { state.configuration = payload; }, - SET_COOKIE(state, cookie) { + SET_COOKIE(state, cookie) { // ! not called anywhere. Delete it ? state.cookie = cookie; }, SET_STATIC_PAGES(state, staticPages) { @@ -175,7 +175,7 @@ export default new Vuex.Store({ } }, - USER_INFO({ state, commit }) { + USER_INFO({ state, commit, dispatch }) { if (!state.user) { axios .get(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}user_info/`) @@ -187,6 +187,7 @@ export default new Vuex.Store({ }) .catch(() => { //* if an url to redirect to an external authentification system is present, do not redirect to the login page + const token = new URLSearchParams(window.location.search).get('token'); if (!state.configuration.VUE_APP_LOGIN_URL) { const url = window.location.href; if (url.includes('projet-partage')) { @@ -195,11 +196,27 @@ export default new Vuex.Store({ } else { router.push({ name: 'login' }); } + } else if (token) { + dispatch('CONNECT_SSO_WITH_TOKEN', token); } }); } }, + async CONNECT_SSO_WITH_TOKEN({commit}, token) { + axios + .get(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}login-token/?token=${token}`) + .then((response) => { + if (response && (response.status === 200 || response.status === 201)) { + const user = response.data; + commit('SET_USER', user); + } + }) + .catch((err) => { + console.error(err); + }) + }, + async GET_USER_TOKEN({ commit }) { const response = await axios.get(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}get-token`); if (