I am facing a strange issue.
I have a logout function which is triggered incase 401 comes in response of any API I hit.
the function is as follows:
logout() {
debugger
this.refreshTokenInProgress = false;
PreAngular.clearAll();
localStorage.clear();
if (window.location.href.indexOf("/public/login") == -1) {
this.router.navigate(["/public/login"]);
}
}
In my app scenario is that I force logout someone from db, and incase they are loggedout if they try to hit any API they are responded with 401 .. I want that as they get 401 they should be loggedout. Whereas rather than logging out it throws an error in typescript of the page I am trying to route on after forcing logout. For example for a page it throws error on below function which is written in NgOnit.
loadData() {
this.formInProgress = true;
this.usersService
.getActiveUsersListing(
this.skip / this.pageSize,
this.pageSize,
this.buildSearchParameters(),
this.activeUserListingForm?.controls["searchInput"].value,
this.dynamicColumns,
this.sort,
)
.subscribe(
(response) => {
this.gridData = response;
console.log(this.gridData);
this.formInProgress = false;
if (!response) this.toastr.error("Error", "No Record Found");
},
(err) => {
console.log("Here in error" + err);
this.toastr.error("Something went wrong");
},
);
}
The console prints Here in errorTypeError: this.router.navigate is not a function
Function loaddata is in xyz.ts which is ts of the page I am opening after forcing logout and above is oauth.ts.
I tried to apply debugger, the code runs all above line of logout and throws error on this.router.navigate line.
Any guidance and way forward would mean a lot please. Thanks