diff --git a/src/store/index.js b/src/store/index.js index faebe1b6157cbcb4a4d572b2edc5be1135af5d9c..ce5d58e6a11272cec3d59b600a3ef15b6c968558 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -30,6 +30,7 @@ export default new Vuex.Store({ map }, state: { + error: null, logged: false, user: false, configuration:null, @@ -43,6 +44,9 @@ export default new Vuex.Store({ }, mutations: { + error(state, data) { + return state.error = data + }, SET_PROJECTS(state, projects) { state.projects = projects; }, @@ -125,15 +129,23 @@ export default new Vuex.Store({ password: payload.password, }) .then((response) => { + commit('error', null) if (response && response.status === 200) { // * use stored previous route to go back after login if page not open on login at first - const routerHistory = router.options.routerHistory[0].name !== "login" ? router.options.routerHistory : "/" + let routerHistory = '' + if (router.options.routerHistory[0] != undefined){ + routerHistory = router.options.routerHistory[0].name !== "login" ? router.options.routerHistory : "/" + } else { + routerHistory = "/" + } commit("SET_USER", response.data.user); router.push(routerHistory[routerHistory.length - 1] || "/") dispatch("GET_USER_LEVEL_PROJECTS"); } }) - .catch(() => { + .catch((error) => { + if (error.response.status === 403) + commit('error', error.response.data.detail) commit("SET_USER", false); }); } diff --git a/src/views/registration/Login.vue b/src/views/registration/Login.vue index 05d38bd0338eef467e39ed8b6647911635d3684f..470d00f3be470f1e4d7b8e989439019d89ba2b92 100644 --- a/src/views/registration/Login.vue +++ b/src/views/registration/Login.vue @@ -62,6 +62,7 @@ <script> +import { mapState } from "vuex"; export default { name: "Login", @@ -76,6 +77,7 @@ export default { }; }, computed: { + ...mapState(["error"]), LOGO_PATH:function () { return this.$store.state.configuration.VUE_APP_LOGO_PATH; }, @@ -87,11 +89,19 @@ export default { }, }, methods: { - login() { + async login() { this.$store.dispatch("LOGIN", { username: this.username_value, password: this.password_value, - }); + }) + .then(() => { + if (this.error != null){ + this.form.errors = "Les informations d'identification sont incorrectes."; + } + }) + .catch(() => { + this.form.errors = this.error + }); }, },