Commit 4efe079e authored by Florent Poittevin's avatar Florent Poittevin
Browse files

fix: 921 fix infinite cancel navigation action

parent d7794a10
import {PersonRole} from "@admin/models/person-role.model";
import {HttpClient} from "@angular/common/http";
import {
ApplicationRole,
Order,
OrganizationalUnit,
Person,
Role,
} from "@models";
import {ApplicationRoleEnum} from "@app/shared/enums/application-role.enum";
import {LanguagesEnum} from "@app/shared/enums/languages.enum";
import {RoutesEnum} from "@app/shared/enums/routes.enum";
......@@ -43,6 +36,13 @@ import {
AppUserStateModel,
} from "@app/stores/user/app-user.state";
import {environment} from "@environments/environment";
import {
ApplicationRole,
Order,
OrganizationalUnit,
Person,
Role,
} from "@models";
import {TranslateService} from "@ngx-translate/core";
import {Navigate} from "@ngxs/router-plugin";
import {
......@@ -66,6 +66,7 @@ import * as moment from "moment";
import {Observable} from "rxjs";
import {
catchError,
mergeMap,
tap,
} from "rxjs/operators";
import {
......@@ -358,8 +359,10 @@ export class AppState extends BasicState<AppStateModel> {
}
@Action(AppAction.Logout)
logout(ctx: StateContext<AppStateModel>): void {
if (isFalse(ctx.getState().isLoggedIn)) {
logout(ctx: StateContext<AppStateModel>): Observable<any> {
const isLoggedIn = ctx.getState().isLoggedIn;
if (isFalse(isLoggedIn)) {
this.oauthService.logOut(true);
return; // PREVENT INFINITE CANCEL LOOP DUE TO MULTIPLE CALL TO THIS METHOD THAT REDIRECT TO HOME PAGE
}
ctx.patchState({
......@@ -371,19 +374,21 @@ export class AppState extends BasicState<AppStateModel> {
});
// Revoke tokens servers side
this.apiService.post(AdminResourceApiEnum.users + urlSeparator + ApiActionEnum.REVOKE_MY_TOKENS).subscribe();
// Logout client side
this.oauthService.logOut();
ctx.dispatch(new Navigate([RoutesEnum.homePage])).subscribe(() => {
ctx.patchState({
ignorePreventLeavePopup: false,
});
if (isTrue(environment.reloadAfterLogout)) {
window.location.reload();
}
});
return this.apiService.post(AdminResourceApiEnum.users + urlSeparator + ApiActionEnum.REVOKE_MY_TOKENS).pipe(
tap(() => {
// Logout client side
this.oauthService.logOut(true);
}),
mergeMap(() => ctx.dispatch(new Navigate([RoutesEnum.homePage]))),
tap(() => {
ctx.patchState({
ignorePreventLeavePopup: false,
});
if (isTrue(environment.reloadAfterLogout)) {
window.location.reload();
}
}),
);
}
@Action(AppAction.CancelPreventExit)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment