I have implemented Okta authentication in my Angular 8 app. When I hit logout button the session is terminated and I am logged out of Okta app but as my logout URL configured in okta is for localhost:4200/dashboard
it redirects me to the dashboard
component. Post successful logout I want to navigate user to localhost:4200/login
. I have two questions, I tried
async logOut(){
await this.oauthService.logout();
this.router.navigate(['/login']);
}
// but this does not redirect user to login.
and also, I tried asking Okta support that logout button is in navbar and can be hit from different URLs and not necessarily localhost:4200/dashboard
as navbar is on every single page of my application. They mentioned it can only be configured from a single URL path. How can I implement the logout from different components and hence different URL paths.
You just need to register a Post Logout Redirect URI and can then trigger logout from any location within your app.
I would implement it like this:
Some resources of mine that might give you some ideas:
Logout blog post
Working logout code