X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fangular%2Fusers%2Fmodels%2Ftoken.ts;h=b7872e74a1fe69583ce796e919518ec5b26c0a69;hb=881a5e68b64e4acd43408852bbdc914643d8fac6;hp=688dfdc803c2d08c83d949a0216be8cd4f7ecefa;hpb=b1794c53ac97d77a16c10ed915336f08cff1e5e3;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/angular/users/models/token.ts b/client/angular/users/models/token.ts index 688dfdc80..b7872e74a 100644 --- a/client/angular/users/models/token.ts +++ b/client/angular/users/models/token.ts @@ -3,13 +3,27 @@ export class Token { refresh_token: string; token_type: string; - constructor (hash) { - this.access_token = hash.access_token; - this.refresh_token = hash.refresh_token; - this.token_type = hash.token_type; + static load(): Token { + return new Token({ + access_token: localStorage.getItem('access_token'), + refresh_token: localStorage.getItem('refresh_token'), + token_type: localStorage.getItem('token_type') + }); } - save() { + 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():void { localStorage.setItem('access_token', this.access_token); localStorage.setItem('refresh_token', this.refresh_token); localStorage.setItem('token_type', this.token_type);