Initially, if the first user is already logged in on the first tab and is redirected to the dashboard, when that same user opens a second tab in the same browser (by pasting the login URL), they are automatically redirected to the dashboard without having to go through the login page. I encountered an issue where there are specific routes on the login page that only unauthenticated users can access.
In the login.component.ts
linkToMarket(): void {
this.sidenav.close().then(() => {
this.router.navigate([UrlConstants.Market]);
});
}
On the Market page (in the second tab), the user can return back to the login page, but unfortunately, they are redirected through the dashboard (as the first user is already logged in) due to the [redirect to dashboard if user is logged in][1] feature. How can I ensure that if there is a different user on the second tab, when returning from the market page, they will not be redirected to the dashboard but instead to the login page? Should I implement a condition on the route or use AuthGuard (CanActivate)?
Detail of login component
ngOnInit(): void {
if (this.authenService.isUserAuthenticated()) {
this.router.navigate([UrlConstants.UserSetting])
}
}
market.component.ts
linkToSignIn(): void {
this.router.navigate([UrlConstants.Login], { queryParams: { returnUrl: UrlConstants.Market } });
if (this.authenService.isUserAuthenticated()) {
this.router.navigate([UrlConstants.Login])
}
}
[1]: https://stackoverflow.com/questions/44121164/angular-2-redirect-if-user-is-logged-in