diff --git a/src/js/stores/user.js b/src/js/stores/user.js index 50eaeb5..39bec7f 100644 --- a/src/js/stores/user.js +++ b/src/js/stores/user.js @@ -48,11 +48,13 @@ const user = createStore({ try { const response = await http.post('/user/login', data); - http.defaults.headers.common['Authorization'] = response.data.token; - await dispatch('setBasicData', response.data ); + if (response.status === 200){ + http.defaults.headers.common['Authorization'] = response.data.token; + await dispatch('setBasicData', response.data ); - delete response.data.token; - delete response.data.roles; + delete response.data.token; + delete response.data.roles; + } return response; } diff --git a/src/pages/login.f7.html b/src/pages/login.f7.html index 7cd1dff..5113ac2 100644 --- a/src/pages/login.f7.html +++ b/src/pages/login.f7.html @@ -65,15 +65,17 @@ export default (props, { $f7, $on, $update, $f7router }) => { }; const result = await user.dispatch('logIn', data); - $f7.preloader.hide(); - if (result.status === 200){ - $f7router.navigate('/'); - $f7.toast.show( { text: "Ha iniciado sesión." }); - } - else{ - $f7.toast.show( { text: result.message }); + if (result.status !== undefined && result.status !== 200){ + $f7.toast.show( { text: result.data.messages.error } ); + $f7.preloader.hide(); + return; } + + $f7.preloader.hide(); + $f7router.navigate('/'); + $f7.toast.show( { text: "Ha iniciado sesión." }); + } catch (error) { $f7.preloader.hide();