Browse Source

[完善]完善刷新token

develop
陈鹏飞 5 years ago
parent
commit
3dd6855a53
  1. 34
      src/app/http-interceptors/cache-token.service.ts

34
src/app/http-interceptors/cache-token.service.ts

@ -5,42 +5,31 @@ import { CookieService } from 'ngx-cookie-service';
@Injectable({
providedIn: 'root'
})
export class CacheTokenService {
constructor(private http:HttpClient,private cookieService: CookieService) { }
public timer;
public settime = null;
//刷新token令牌定时器
startUp = ():void=>{
// this.getmenus();
this.timer = window.setInterval(
()=>{
window.clearInterval(this.settime)
var token = this.cookieService.get("token");
var refreshToken = this.cookieService.get("refreshToken");
this.http.post(
'/api/CompanyAccount/RefreshToken',
{
token: token,
refreshToken: refreshToken
}
).subscribe(
(data:any) => {
window.clearInterval(this.timer)
this.timer = window.setInterval( ()=>{
var token = this.cookieService.get("token");
var refreshToken = this.cookieService.get("refreshToken");
this.http.post('/api/CompanyAccount/RefreshToken',
{
token: token,
refreshToken: refreshToken}).subscribe( (data:any) => {
this.cookieService.set("token",data.token,null,'/');
this.cookieService.set("refreshToken",data.refreshToken,null,'/');
}
)
}
,18*60*1000)
})
} ,18*60*1000)
}
//删除定时器
delete = ():void=> {
@ -51,5 +40,4 @@ export class CacheTokenService {
var newtime = time.substr(0,4) + '年' + time.substr(5,2) + '月' + time.substr(8,2) + '日' + time.substr(11,8)
}
}

Loading…
Cancel
Save