From 1e13abc752d72b2ae3081ad411462c96645285d3 Mon Sep 17 00:00:00 2001 From: pawlaczyk Date: Sat, 12 Jan 2019 23:06:55 +0100 Subject: [PATCH] [token front] poprawiony + store --- frontend/app/src/components/Navbar.vue | 5 +++-- frontend/app/src/router.js | 17 ----------------- frontend/app/src/store/store.js | 18 ------------------ frontend/app/src/views/Cards.vue | 17 +++++++---------- frontend/app/src/views/Game.vue | 15 ++++++--------- frontend/app/src/views/Users.vue | 17 +++++++---------- 6 files changed, 23 insertions(+), 66 deletions(-) diff --git a/frontend/app/src/components/Navbar.vue b/frontend/app/src/components/Navbar.vue index b0169a7..f4c0827 100644 --- a/frontend/app/src/components/Navbar.vue +++ b/frontend/app/src/components/Navbar.vue @@ -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 diff --git a/frontend/app/src/router.js b/frontend/app/src/router.js index cbeb378..4d8812c 100644 --- a/frontend/app/src/router.js +++ b/frontend/app/src/router.js @@ -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', diff --git a/frontend/app/src/store/store.js b/frontend/app/src/store/store.js index 1d15ebe..4e6a242 100644 --- a/frontend/app/src/store/store.js +++ b/frontend/app/src/store/store.js @@ -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; - } } }) diff --git a/frontend/app/src/views/Cards.vue b/frontend/app/src/views/Cards.vue index 90f2a80..3cad9a2 100644 --- a/frontend/app/src/views/Cards.vue +++ b/frontend/app/src/views/Cards.vue @@ -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')) + } } diff --git a/frontend/app/src/views/Game.vue b/frontend/app/src/views/Game.vue index 950823d..209a89b 100644 --- a/frontend/app/src/views/Game.vue +++ b/frontend/app/src/views/Game.vue @@ -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')) } } diff --git a/frontend/app/src/views/Users.vue b/frontend/app/src/views/Users.vue index 703fdf5..7ad6447 100644 --- a/frontend/app/src/views/Users.vue +++ b/frontend/app/src/views/Users.vue @@ -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')) + } }