88082: Issue #1136 - Forgot/Register links loading fix

This commit is contained in:
Kristof De Langhe
2022-03-01 15:11:25 +01:00
parent 9fc7b57157
commit 7924db512b
15 changed files with 223 additions and 42 deletions

View File

@@ -197,19 +197,27 @@ export const getAllSucceededRemoteListPayload = <T>() =>
*
* @param router The router used to navigate to a new page
* @param authService Service to check if the user is authenticated
* @param navigateAction Optional action to take with the Promise returned by navigateByUrl
*/
export const redirectOn4xx = <T>(router: Router, authService: AuthService) =>
// tslint:disable-next-line:no-empty
export const redirectOn4xx = <T>(router: Router, authService: AuthService, navigateAction?: (nav: boolean) => void) =>
(source: Observable<RemoteData<T>>): Observable<RemoteData<T>> =>
source.pipe(
withLatestFrom(authService.isAuthenticated()),
filter(([rd, isAuthenticated]: [RemoteData<T>, boolean]) => {
if (rd.hasFailed) {
if (rd.statusCode === 404 || rd.statusCode === 422) {
router.navigateByUrl(getPageNotFoundRoute(), { skipLocationChange: true });
const promise = router.navigateByUrl(getPageNotFoundRoute(), { skipLocationChange: true });
if (hasValue(navigateAction)) {
promise.then(navigateAction);
}
return false;
} else if (rd.statusCode === 403 || rd.statusCode === 401) {
if (isAuthenticated) {
router.navigateByUrl(getForbiddenRoute(), { skipLocationChange: true });
const promise = router.navigateByUrl(getForbiddenRoute(), { skipLocationChange: true });
if (hasValue(navigateAction)) {
promise.then(navigateAction);
}
return false;
} else {
authService.setRedirectUrl(router.url);