Skip to content
Snippets Groups Projects
Commit b9f885f9 authored by Timothee P's avatar Timothee P :sunflower:
Browse files

fix: detection de redirection pour logout SSO

parent 170fc9d8
No related branches found
No related tags found
1 merge request!866REDMINE_ISSUE-24200 | Déconnexion OGS <-> GC
......@@ -104,15 +104,33 @@ const updateOnlineStatus = () => {
/**
* Regularly updates the user status if using external auth to keep the frontend updated with backend.
*/
function handleLogout() {
if (store.state.user) {
store.dispatch('LOGOUT');
store.commit('DISPLAY_MESSAGE', {
level: 'negative',
comment: `Vous avez été déconnecté du service d'authentification.
Reconnectez-vous ou continuez en mode anonyme.`
});
store.dispatch('GET_USER_LEVEL_PROJECTS');
}
}
const updateUserStatus = () => {
setInterval(() => {
if (navigator.onLine) {
axios
.get(`${store.state.configuration.VUE_APP_DJANGO_API_BASE}user_info/`)
.then((response) => {
if (response && response.status === 200) {
const user = response.data.user;
if (!store.state.user && user) {
const user = response.data?.user || null;
if (response.status === 302) {
console.warn("Redirection détectée vers :", response.headers.location || response.request.responseURL);
}
if (response.status === 200 && user) {
// Cas où l'utilisateur est bien authentifié
if (!store.state.user) {
store.commit('SET_USER', user);
store.commit('DISPLAY_MESSAGE', {
level: 'positive',
......@@ -121,28 +139,15 @@ const updateUserStatus = () => {
store.dispatch('GET_USER_LEVEL_PERMISSIONS');
store.dispatch('GET_USER_LEVEL_PROJECTS');
}
} else if (store.state.user) {
} else if (!user) {
// Lorsqu'un utilisateur est déconnecté du SSO, la requête de vérification de session envoyée à l'API de l'application échoue avec une erreur 400.
// On force la déconnexion de l'utilisateur dans ce cas.
store.dispatch('LOGOUT')
store.commit('DISPLAY_MESSAGE', {
level: 'negative',
comment: `Vous avez été déconnecté du service d'authentification.
Reconnectez-vous ou continuez en mode anonyme.`
});
handleLogout();
}
})
.catch(() => {
if (store.state.user) {
store.commit('SET_USER', false);
store.commit('DISPLAY_MESSAGE', {
level: 'negative',
comment: `Vous avez été déconnecté du service d'authentification.
Reconnectez-vous ou continuez en mode anonyme.`
});
store.dispatch('GET_USER_LEVEL_PERMISSIONS');
store.dispatch('GET_USER_LEVEL_PROJECTS');
}
.catch(error => {
console.error("Erreur API :", error);
handleLogout();
});
}
}, 10000);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment