提交 fec51d81 编写于 作者: tony001's avatar tony001

新增应用刷新token逻辑 --- fix2

上级 198d197f
......@@ -107,6 +107,9 @@ export class Interceptors {
});
axios.interceptors.response.use((response: any) => {
if(response.headers && response.headers['refreshtoken'] && localStorage.getItem('token')){
this.refreshToken();
}
return response;
}, (error: any) => {
error = error ? error : { response: {} };
......@@ -120,11 +123,7 @@ export class Interceptors {
res.data.entityName = res.headers['x-ibz-params'];
}
if (res.status === 401) {
if(res.headers && res.headers['refreshToken'] && localStorage.getItem('token')){
this.refreshToken(_data.data);
}else{
this.doNoLogin(_data.data);
}
this.doNoLogin(_data.data);
}
if(res.status === 403){
if(res.data && res.data.status && Object.is(res.data.status,"FORBIDDEN")){
......@@ -185,22 +184,21 @@ export class Interceptors {
* 刷新token
*
* @private
* @param {*} [data={}]
* @memberof Interceptors
*/
private refreshToken(data: any = {}):void{
Http.getInstance().post('/uaa/refreshToken',{oldToken:localStorage.getItem('token')},false).then((response: any) => {
private refreshToken():void{
Http.getInstance().post('/uaa/refreshToken',localStorage.getItem('token'),false).then((response: any) => {
if (response && response.status === 200) {
const data = response.data;
if (data && data.token) {
localStorage.setItem('token', data.token);
Util.setCookie('ibzuaa-token',data.token,0);
if (data ) {
localStorage.setItem('token', data);
Util.setCookie('ibzuaa-token',data,0);
}
}else{
this.doNoLogin(data);
console.log("刷新token出错");
}
}).catch((error: any) => {
this.doNoLogin(data);
console.log("刷新token出错");
});
}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册