Created
April 25, 2020 19:09
-
-
Save thiagodomingues/455533e541603549bb01156bede6e7ee to your computer and use it in GitHub Desktop.
help me bro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import store from '../store' | |
export default async (to, from, next) => { | |
console.log('logado', store.getters['auth/isAuthenticated']); | |
if (to.name !== 'Login' && !store.getters['auth/isAuthenticated']) next({ name: 'Login' }) | |
else next() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import http from '@/http' | |
export const doLogin = (userInfo) => { | |
return http().get(`/sanctum/csrf-cookie`).then(() => { | |
return http().post(`/api/v1/common/login`, { | |
email: userInfo.email, | |
password: userInfo.password | |
}).then((response) => { | |
return response; | |
}); | |
}) | |
}; | |
export const doLogout = () => { | |
return http().post(`/api/v1/common/logout`).then((response) => { | |
return response.data; | |
}); | |
} | |
export const me = () => { | |
return http().get("api/v1/common/me").then((response) => { | |
console.log('me entrou'); | |
return response; | |
}).catch(() => { | |
console.log('me falhou'); | |
return null; | |
}); | |
} | |
export default { | |
doLogin, | |
doLogout, | |
me, | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Vue from 'vue' | |
import App from './App.vue' | |
import router from './router' | |
import store from './store' | |
import './registerServiceWorker'; | |
import './components/components' | |
import './plugins/chartist' | |
import './plugins/vee-validate' | |
import vuetify from './plugins/vuetify' | |
import VueSweetalert2 from 'vue-sweetalert2'; | |
Vue.use(VueSweetalert2); | |
Vue.config.productionTip = false | |
store.dispatch('auth/ActionMeLogin').then(() => { | |
console.log('teste 1'); | |
new Vue({ | |
vuetify, | |
router, | |
store, | |
render: h => h(App), | |
}).$mount('#app') | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import LoginService from '../services/LoginService' | |
import * as types from './mutation-types'; | |
export const ActionDoLogin = ({ commit }, payload) => { | |
LoginService.doLogin(payload).then((response) => { | |
console.log('actionDoLogin'); | |
if (!response.status && response.status != 401) { | |
commit(types.SET_USER_AUTHENTICATED, true); | |
commit(types.SET_USER, response.data) | |
} else { | |
console.log('autenticado nao'); | |
commit(types.SET_USER_AUTHENTICATED, false); | |
store.dispatch('ActionSetUser', null); | |
} | |
}); | |
} | |
export const ActionDoLogout = ({ commit }, payload) => { | |
LoginService.doLogout(payload).then((response) => { | |
commit(types.SET_USER, {}) | |
commit(types.SET_USER_AUTHENTICATED, false); | |
}); | |
} | |
export const ActionMeLogin = ({ commit }, store, payload) => { | |
LoginService.me(payload).then((response) => { | |
if (!response.status && response.status != 401) { | |
console.log('Me sim'); | |
commit(types.SET_USER_AUTHENTICATED, true); | |
console.log(response.data); | |
commit(types.SET_USER, response.data) | |
} else { | |
console.log('Me nao'); | |
commit(types.SET_USER_AUTHENTICATED, false); | |
store.dispatch('ActionSetUser', null); | |
} | |
}).catch(() => { | |
console.log('pipocou'); | |
return null; | |
});; | |
} | |
export const ActionSetUser = ({ commit }, payload) => { | |
commit(types.SET_USER, payload) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment