-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathauth.js
40 lines (24 loc) · 860 Bytes
/
auth.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
import api from 'trim/js/library/api.js';
import auth from 'trim/js/library/auth.js';
export default auth.extend({
isUserLogged() {
return Boolean(localStorage.getItem('accessToken'));
},
loginWithCredentials(credentials) {
return new Promise((resolve, reject) => {
if (credentials.username.length && credentials.password.length) {
localStorage.setItem('accessToken', 'testToken');
resolve();
} else {
reject(new Error('Login failed'));
}
});
},
onAuthorization() {
api.defaults.headers.common.Authorization = 'Bearer ' + localStorage.getItem('accessToken');
},
onDeauthorization() {
localStorage.removeItem('accessToken');
delete api.defaults.headers.common.Authorization;
}
});