Skip to content
Snippets Groups Projects
Commit 1024ff05 authored by Sébastien DA ROCHA's avatar Sébastien DA ROCHA :bicyclist:
Browse files

Merge branch 'ticket/11714' into 'develop'

add error in user store

See merge request geocontrib/geocontrib-frontend!13
parents c9b6bcc3 0749df73
No related branches found
No related tags found
Loading
......@@ -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);
});
}
......
......@@ -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
});
},
},
......
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