aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/app/users/shared/token.model.ts
blob: 021c83fadee41295a248e779df2dac51d7765bf5 (plain) (blame)
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
export class Token {
  access_token: string;
  refresh_token: string;
  token_type: string;

  static load() {
    return new Token({
      access_token: localStorage.getItem('access_token'),
      refresh_token: localStorage.getItem('refresh_token'),
      token_type: localStorage.getItem('token_type')
    });
  }

  constructor(hash?: any) {
    if (hash) {
      this.access_token = hash.access_token;
      this.refresh_token = hash.refresh_token;

      if (hash.token_type === 'bearer') {
        this.token_type = 'Bearer';
      } else {
        this.token_type = hash.token_type;
      }
    }
  }

  save() {
    localStorage.setItem('access_token', this.access_token);
    localStorage.setItem('refresh_token', this.refresh_token);
    localStorage.setItem('token_type', this.token_type);
  }
}