I have simplistic Angular2 app, where if user clicks on the
<a class="dropdown-item" (click)=authService.logout() href="/welcome">Log out</a>
logout menu item, the AuthenticationServices's logout()
method executes
logout() {
alert('loging out');
this.authHttp.post(this.endpoint_url + '/auth/logout','').map(res => {
if(res.status == 204) alert('logout successful');
else alert('logout failed');
});
this.currentUser = null;
localStorage.removeItem('token');
}
the problem is the part
this.authHttp.post(this.endpoint_url + '/auth/logout','').map(res => {
if(res.status == 204) alert('logout successful');
else alert('logout failed');
});
does not seem to be ever executed. Accessing protected API with authHttp
(angular2-jwt) works in other parts of application without any problems.
The first alert "loging out" pops, users is logged out and redirected to "/welcome" and can no longer access private parts of API. However, there is no request to "/auth/logout" in browser nor in server logs.
There is also AuthGuard
service that redirects any non-logged users:
canActivate() {
//loggedIn() {!(this.currentUser == null);}
if (!this.auth.loggedIn()) {
this.router.navigate(['/welcome']);
return false;
}
return true;
}