-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
41 lines (38 loc) · 1018 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// axios api
let config = {
baseURL: '{{base}}api.v1/',
timeout: 8000,
headers: {'X-Custom-Header': 'foobar'}
};
if(localStorage.token){
config.headers.Authorization = `Bearer ${localStorage.token.replace('"','')}`;
}
const api = axios.create(config);
// "session" mixin
const session = {
data: function(){
return {
token: localStorage.token,
validThrough: localStorage.validThrough,
user: {},
expiration: new Date(Number(localStorage.validThrough))
}
},
created(){
try{
this.user = JSON.parse(localStorage.user);
} catch (e) {
this.user = {}
}
},
methods: {
refreshToken: function(){
api.put('login').then(result =>{
['token','validThrough'].forEach((prop) => {
localStorage.setItem(prop,result.data[prop]);
this._data[prop] = result.data[prop];
});
})
}
}
};