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:
parent
46c5f74b49
commit
2656a67fca
@ -137,7 +137,17 @@ export class AppComponent implements OnInit, OnDestroy {
|
|||||||
this.router.navigate(['loggedout'], { queryParams: { redirectTo: this.router.url } });
|
this.router.navigate(['loggedout'], { queryParams: { redirectTo: this.router.url } });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(event.type == 'token_received') {
|
||||||
|
this.store$.dispatch(new commonActions.InitUser());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
if(this.oauthService$.hasValidAccessToken) {
|
||||||
|
this.store$.dispatch(new commonActions.InitUser());
|
||||||
|
} else {
|
||||||
|
if(this.oauthService$.getRefreshToken() !=null) {
|
||||||
|
this.oauthService$.refreshToken();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private InstallRouteEventHandler() {
|
private InstallRouteEventHandler() {
|
||||||
|
@ -202,12 +202,10 @@ export class AppCommonEffects {
|
|||||||
console.debug("No valid token, try to refresh");
|
console.debug("No valid token, try to refresh");
|
||||||
if(this.oauthService$.getRefreshToken() != null ) {
|
if(this.oauthService$.getRefreshToken() != null ) {
|
||||||
console.debug("We have a refresh token");
|
console.debug("We have a refresh token");
|
||||||
this.oauthService$.refreshToken().then(() => {
|
this.oauthService$.refreshToken();
|
||||||
this.store$.dispatch(new appCommonActions.InitUser());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return of(undefined);
|
return of(undefined);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
@ -41,24 +41,9 @@ export class AuthGuard implements CanActivate, CanLoad, CanActivateChild {
|
|||||||
return new Promise<boolean>((resolve) => {
|
return new Promise<boolean>((resolve) => {
|
||||||
if (!this.oauthService.hasValidAccessToken()) {
|
if (!this.oauthService.hasValidAccessToken()) {
|
||||||
console.debug("No valid token");
|
console.debug("No valid token");
|
||||||
if(this.oauthService.getRefreshToken() != null ) {
|
this.oauthService.initCodeFlow(url);
|
||||||
console.debug("We have a refresh token");
|
resolve(false);
|
||||||
this.oauthService.refreshToken().then(() => {
|
} else {
|
||||||
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());
|
|
||||||
resolve(true);
|
resolve(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -55,14 +55,17 @@ export class ItemTypeService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public load(config:AppConfig): Promise<any> {
|
public load(config:AppConfig): Promise<any> {
|
||||||
|
if(this.itemTypes==null) {
|
||||||
var url = `${ config.getConfig("apiEndPoint")}/api/v1/itemtypes/`
|
var url = `${ config.getConfig("apiEndPoint")}/api/v1/itemtypes/`
|
||||||
return this.httpClient.get(url)
|
return this.httpClient.get(url)
|
||||||
.toPromise()
|
.toPromise()
|
||||||
.then((itemTypes:IItemTypes) => {
|
.then((itemTypes:IItemTypes) => {
|
||||||
this.itemTypes = itemTypes;
|
this.itemTypes = itemTypes;
|
||||||
//return data;
|
//return data;
|
||||||
})
|
})
|
||||||
.catch(error => this.itemTypes = null);
|
.catch(error => this.itemTypes = null);
|
||||||
|
} else {
|
||||||
|
return new Promise((resolve) => {resolve()});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user