I'm new to Vue.js, and I have used Laravel 5.4 as back-end for my project. I did the authentication by using Passport on Laravel and Navigation guards on Vue.js to protect my route on front end, but now I want to do authorization after the user successfully authenticated and store his token on local storage, I want to do authorization based on user role (each role has some of the permissions).
Is there any suggestion for a tutorial to follow?
This my auth. package on Vue.js:
export default function(Vue) {
Vue.auth= {
setToken(tocken,expiration){
localStorage.setItem('Tocken',tocken);
localStorage.setItem('expiration',expiration);
},
getToken() {
var token = localStorage.getItem('Tocken')
var expiration = localStorage.getItem('expiration')
if(!token || !expiration)
return null
if (Date.now() > parseInt(expiration)) {
this.destroyToken()
return null
} else
return token
},
destroyToken() {
localStorage.removeItem('Tocken')
localStorage.removeItem('expiration')
},
// enter code here
isAuthnticated() {
if(this.getToken()){
return true;
} else
return false;
}
}
//Object.defineProperty(Vue.prototype)
Object.defineProperties(Vue.prototype, {
$auth:{
get: ()=>{
return Vue.auth
}
}
})
}