Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export const login = ({ commit, dispatch }, dataLogin) => {
- commit(mutationsTypes.LOGIN)
- const { axios } = dataLogin
- return new Promise((resolve, reject) => {
- dataLogin.email = dataLogin.email.trim()
- const { email, password } = dataLogin
- console.log('caiu aqui, valor de axios', axios)
- axios
- .post('/login', { email, password })
- .then(async (response) => {
- console.log('caiu no then')
- if (response.data.success) {
- await dispatch('setToken', response.data.data.token)
- await dispatch('setUser', response.data.data.user)
- await commit(mutationsTypes.LOGIN_SUCCESS, response.data.data.token)
- resolve()
- }
- })
- .catch(async (response) => {
- console.log('caiu no catch')
- await dispatch('setToken', null)
- await dispatch('setUser', null)
- await commit(mutationsTypes.LOGIN_ERROR, 'Usuário ou senha incorretos')
- reject((response.data && response.data.message) ? response.data.message : 'Usuário ou senha incorretos')
- })
- }).then((value) => {
- console.log('caiu no then 2')
- if (dataLogin.redirect) router.push(dataLogin.redirect)
- else router.push('/home')
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement