[token front] poprawiony + store
This commit is contained in:
parent
fc355ad417
commit
1e13abc752
@ -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
|
||||
|
@ -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',
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -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'))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user