[token front] poprawiony + store

This commit is contained in:
pawlaczyk 2019-01-12 23:06:55 +01:00
parent fc355ad417
commit 1e13abc752
6 changed files with 23 additions and 66 deletions

View File

@ -110,8 +110,9 @@ export default {
this.snackbarLogout = true
this.isLogged = false
console.log("wylogowano")
// window.location.replace("http://localhost:8080");
localStorage.setItem('token',null);
localStorage.setItem('user', null);
this.$router.push('/')
}
else{
this.snackbarLogout = false

View File

@ -6,27 +6,10 @@ import Cards from '@/views/Cards'
import Login from '@/views/Login'
import Logout from '@/views/Logout'
import Register from '@/views/Register'
import store from '@/store/store'
Vue.use(Router)
const ifNotAuthenticated = (to, from, next) => {
if (!store.getters.isAuthenticated) {
next()
return
}
next('/')
}
const ifAuthenticated = (to, from, next) => {
if (store.getters.isAuthenticated) {
next()
return
}
next('/login')
}
export default new Router({
mode: 'history',

View File

@ -14,23 +14,5 @@ export const store = new Vuex.Store({
// { icon: 'get_app', text: 'Zaloguj', route: '/login'},
// { icon: 'account_circle', text: 'Rejestracja', route: '/register'},
],
token: null, // na przechoywanie tokena z GO dla usera
user: null
},
getters:{
userToken: state => {//getter do pobieranie user tokena
var userToken = state.token.map(token => {
return {
token
}
});
return userToken;
}
},
mutations: {
LOGIN_SUCCESS(state, response) {
state.token = response;
}
}
})

View File

@ -151,23 +151,20 @@ export default {
},
created(){
//Zbuduje sie tylko i wylacznie wtedy gdy uzytkownik jest zalogowany, w przeciwnym wypadku przekierowuj do zalogowania
var local = localStorage.getItem('token');
var localU = localStorage.getItem('user');
console.log("localStorage.getItem('token')" , localStorage.getItem('token'))
if (localStorage.getItem('token')){
if (localStorage.getItem('token') === "null"){
this.isLogged = true
console.log("TUTAJ: ", localStorage.getItem('token') === null)
}
else{
this.$router.push('/')
}
if(localStorage.getItem('token') === null){
this.$router.push('/')
console.log("LOCAL STOARAGE: ", local)
console.log("LOCAL STOARAGE User: ", localU)
}
}
console.log("LOCAL STOARAGE: ", localStorage.getItem('token'))
console.log("LOCAL STOARAGE User: ", localStorage.getItem('user'))
}
}

View File

@ -88,22 +88,19 @@ export default {
},
created(){
//Zbuduje sie tylko i wylacznie wtedy gdy uzytkownik jest zalogowany, w przeciwnym wypadku przekierowuj do zalogowania
var local = localStorage.getItem('token');
var localU = localStorage.getItem('user');
console.log("localStorage.getItem('token')" , localStorage.getItem('token'))
if (localStorage.getItem('token')){
if (localStorage.getItem('token') === "null"){
this.isLogged = true
console.log("TUTAJ: ", localStorage.getItem('token') === null)
}
else{
this.$router.push('/')
}
if(localStorage.getItem('token') === null){
this.$router.push('/')
console.log("LOCAL STOARAGE: ", local)
console.log("LOCAL STOARAGE User: ", localU)
}
console.log("LOCAL STOARAGE: ", localStorage.getItem('token'))
console.log("LOCAL STOARAGE User: ", localStorage.getItem('user'))
}
}
</script>

View File

@ -86,23 +86,20 @@ export default {
created(){
//Zbuduje sie tylko i wylacznie wtedy gdy uzytkownik jest zalogowany, w przeciwnym wypadku przekierowuj do zalogowania
var local = localStorage.getItem('token');
var localU = localStorage.getItem('user');
console.log("localStorage.getItem('token')" , localStorage.getItem('token'))
if (localStorage.getItem('token')){
if (localStorage.getItem('token') === "null"){
this.isLogged = true
console.log("TUTAJ: ", localStorage.getItem('token') === null)
}
else{
this.$router.push('/')
}
if(localStorage.getItem('token') === null){
this.$router.push('/')
console.log("LOCAL STOARAGE: ", local)
console.log("LOCAL STOARAGE User: ", localU)
}
}
console.log("LOCAL STOARAGE: ", localStorage.getItem('token'))
console.log("LOCAL STOARAGE User: ", localStorage.getItem('user'))
}
}
</script>