Skip to content
Snippets Groups Projects
Commit 4fb363a5 authored by Camille Blanchon's avatar Camille Blanchon
Browse files

Merge branch 'redmine-issues/17962' into 'develop'

REDMINE_ISSUE-17962 | Si je change d'utilisateur dans le WP, je ne suis pas connectée avec le bon utilisateur dans GéoContrib

See merge request !608
parents cf1f2fe7 af1c2a8b
Branches
Tags
1 merge request!608REDMINE_ISSUE-17962 | Si je change d'utilisateur dans le WP, je ne suis pas connectée avec le bon utilisateur dans GéoContrib
......@@ -179,7 +179,12 @@ export default new Vuex.Store({
}
},
USER_INFO({ state, commit, dispatch }) {
async USER_INFO({ state, commit, dispatch }) {
const token = new URLSearchParams(window.location.search).get('token');
// if user was previously connected through SSO, make sure he's logout before connecting through SSO, in case user changed
if (token && this.state.configuration.VUE_APP_LOGIN_URL) {
await dispatch('LOGOUT');
}
if (!state.user) {
axios
.get(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}user_info/`)
......@@ -191,7 +196,6 @@ 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')) {
......@@ -211,9 +215,9 @@ export default new Vuex.Store({
}
},
async CONNECT_SSO_WITH_TOKEN({ commit, dispatch }, token) {
async CONNECT_SSO_WITH_TOKEN({ state, commit, dispatch }, token) {
axios
.get(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}login-token/?token=${token}`)
.get(`${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;
......@@ -233,8 +237,8 @@ export default new Vuex.Store({
});
},
async GET_USER_TOKEN({ commit }) {
const response = await axios.get(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}get-token`);
async GET_USER_TOKEN({ state, commit }) {
const response = await axios.get(`${state.configuration.VUE_APP_DJANGO_API_BASE}get-token`);
if (
response.status === 200 &&
response.data
......@@ -243,21 +247,24 @@ export default new Vuex.Store({
}
},
LOGOUT({ commit, dispatch }) {
axios
.get(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}logout/`)
LOGOUT({ state, commit, dispatch }) {
return axios
.get(`${state.configuration.VUE_APP_DJANGO_API_BASE}logout/`)
.then((response) => {
if (response && response.status === 200) {
commit('SET_USER', false);
commit('SET_USER_LEVEL_PROJECTS', null);
dispatch('GET_USER_LEVEL_PERMISSIONS');
if (router.history.current.name !== 'index' && !window.location.pathname.includes('projet-partage')) {
if (router.history.current.name !== 'index' &&
!window.location.pathname.includes('projet-partage') &&
!state.configuration.VUE_APP_LOGIN_URL
) {
router.push('/');
}
}
})
.catch((error) => {
throw error;
console.error(error);
});
},
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment