Can you please let me know how we can use the logout feature of the nebluar auth. As no server side will be needed for the logout feature just need to destroy the stored token on the client side. Then why we need to add the logout endpoint in the app.module? and no documentation is present in the docs regarding this. Please guide
Thanks @danshou, this is the way.
@danshou @nnixaa the reference no longer working.
using an empty endpoint will still trigger the logout HTTP call which should provide the JWT token.
Any other better solution to do this?
@crossRT can you provide some code? Maybe you are injecting a valid url and by leaving the logout endpoint with just '/' will still be a valid url, not an empty endpoint.
@crossRT I might have found a solution:
logout: {
method: null,
redirect: {
success: '/',
failure: '/'
}
},
Using this configuration will not trigger any http requests upon logout and redirect the user to any given url.
@FatSquirrel93 Thanks for your solution, but still JWT token not deleted, how can i delete that? I have tried the other solutions but nothing worked.
@FatSquirrel93 Thanks for your solution, but still JWT token not deleted, how can i delete that? I have tried the other solutions but nothing worked.
I created a custom LogoutComponent (https://akveo.github.io/nebular/docs/auth/custom-auth-components), override logout to call .clear() on NbTokenService.
Something like this:
```ts, diff
// ...
export class LogoutComponent extends NbLogoutComponent implements OnInit {
constructor(
protected service: NbAuthService,
@Inject(NB_AUTH_OPTIONS) protected options = {},
protected router: Router,
protected tokenService: NbTokenService
) {
super(service, options, router);
}
ngOnInit() {
super.ngOnInit();
}
logout(strategy: string): void {
super.logout(strategy);
this.tokenService.clear();
}
}
```
Referring to https://github.com/akveo/nebular/issues/38#issuecomment-370788867:
Seems like during logout, result.isSuccess() always return false which will skip deleting the token.
Just call this.router.navigate
onContecxtItemSelection(title) {
if (title === 'Log out') {
this.router.navigate(['admin/auth/logout']);
}
}
@drav96 In which file we have to add this code part ?
I solve my logout problem using the default params of logout in NbPasswordAuthStrategy. In my scenario endpoint: 'logout', method: 'delete', and baseEndpoint = '/api/auth/', so my backend need to handle /api/auth/logout as shows:
app.delete('`/api/auth/logout', (req, res, next) => {
return res.status(204).json({});
});
With this, logout() at nebular auth.service.ts will clear the JWT Token.
Most helpful comment
@FatSquirrel93 Thanks for your solution, but still JWT token not deleted, how can i delete that? I have tried the other solutions but nothing worked.