Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export default function(Vue) {
- Vue.auth = {
- setToken (token, expiration) {
- localStorage.setItem('token', token)
- localStorage.setItem('expiration', expiration)
- },
- getToken () {
- var token = localStorage.getItem('token');
- 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('expiration')
- localStorage.removeItem('token')
- },
- isAuthenticated () {
- if(this.getToken()){
- return true
- }else{
- return false
- }
- }
- }
- Object.defineProperties(Vue.prototype, {
- $auth:{
- get () {
- return Vue.auth;
- }
- }
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement