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

feat: add redirect to login page from api response

parent 0cb63206
No related branches found
No related tags found
1 merge request!822REDMINE_ISSUE-18860 | Authentification GéoContrib via API OGS
......@@ -183,14 +183,18 @@ export default new Vuex.Store({
});
}
},
/**
* Action to retrieve user information.
* - If a token is present in the URL, it indicates a Single Sign-On (SSO) attempt,
* in which case it logs out the user (if logged in) and connects via SSO with the token.
* Otherwise, it fetches user information from the Django API endpoint:
* - If no user is logged AND if the login should be done through SSO with a redirect,
* it naviguates to the login plateform, afterwards the user will be redirected with the token and the original url to open in geocontrib
* - Else it displays a message that the user is not logged but can still access the app as an anonymous user.
* - If a token is present in the URL, it indicates a Single Sign-On (SSO) attempt,
* in which case it logs out the user (if logged in) and connects via SSO with the token.
* - Otherwise, it fetches user information from the Django API endpoint:
* - If no user is logged in AND if the login should be done through SSO with a redirect,
* it navigates to the login platform. Afterward, the user will be redirected with the token and the original URL to open in Geocontrib.
* - Else if the response contains a login_url (to connect with OGS), the user is redirected to this url which will redirect the user
* to geocontrib after login, which will check again if the OGS session is activated
* - Otherwise, it displays a message that the user is not logged in but can still access the app as an anonymous user.
* A 'next' parameter is added to transfer to the OGS login page for redirection.
*/
async GET_USER_INFO({ state, commit, dispatch }) {
// Extract token from URL query parameters
......@@ -211,10 +215,12 @@ export default new Vuex.Store({
// Update the user state with received user data
if (response && response.status === 200) {
const user = response.data.user;
console.log('user', user);
commit('SET_USER', user);
}
})
.catch(() => {
.catch((error) => {
const response = error.response;
// If the instance is set to accept login with redirection
if (state.configuration.VUE_APP_SSO_LOGIN_URL_WITH_REDIRECT) {
commit('DISPLAY_MESSAGE', {
......@@ -222,6 +228,9 @@ export default new Vuex.Store({
});
// Call the SSO login plateform with url to redirect after login
window.open(`${state.configuration.VUE_APP_SSO_LOGIN_URL_WITH_REDIRECT}/?url_redirect=${encodeURIComponent(currentUrl)}`, '_self');
} else if (response && response.data.redirect) {
// If the backend return a login url, the user is redirected to connect through OGS login
window.location.href = response.data.login_url;
} else {
// If the user is not logged in, display an info message
commit('DISPLAY_MESSAGE', {
......
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