Refactor token refresh flows
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good
This commit is contained in:
@@ -41,24 +41,9 @@ export class AuthGuard implements CanActivate, CanLoad, CanActivateChild {
|
||||
return new Promise<boolean>((resolve) => {
|
||||
if (!this.oauthService.hasValidAccessToken()) {
|
||||
console.debug("No valid token");
|
||||
if(this.oauthService.getRefreshToken() != null ) {
|
||||
console.debug("We have a refresh token");
|
||||
this.oauthService.refreshToken().then(() => {
|
||||
this.store.dispatch(new appCommonActions.InitUser());
|
||||
resolve(true);
|
||||
}).catch(() => {
|
||||
console.debug("Error refreshing");
|
||||
this.oauthService.initCodeFlow(url);
|
||||
resolve(false);
|
||||
})
|
||||
} else {
|
||||
console.debug("No refresh token");
|
||||
this.oauthService.initCodeFlow(url);
|
||||
resolve(false);
|
||||
}
|
||||
} else {
|
||||
console.debug("Valid token init user");
|
||||
this.store.dispatch(new appCommonActions.InitUser());
|
||||
this.oauthService.initCodeFlow(url);
|
||||
resolve(false);
|
||||
} else {
|
||||
resolve(true);
|
||||
}
|
||||
});
|
||||
|
@@ -55,14 +55,17 @@ export class ItemTypeService {
|
||||
}
|
||||
|
||||
public load(config:AppConfig): Promise<any> {
|
||||
|
||||
var url = `${ config.getConfig("apiEndPoint")}/api/v1/itemtypes/`
|
||||
return this.httpClient.get(url)
|
||||
.toPromise()
|
||||
.then((itemTypes:IItemTypes) => {
|
||||
this.itemTypes = itemTypes;
|
||||
//return data;
|
||||
})
|
||||
.catch(error => this.itemTypes = null);
|
||||
if(this.itemTypes==null) {
|
||||
var url = `${ config.getConfig("apiEndPoint")}/api/v1/itemtypes/`
|
||||
return this.httpClient.get(url)
|
||||
.toPromise()
|
||||
.then((itemTypes:IItemTypes) => {
|
||||
this.itemTypes = itemTypes;
|
||||
//return data;
|
||||
})
|
||||
.catch(error => this.itemTypes = null);
|
||||
} else {
|
||||
return new Promise((resolve) => {resolve()});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user