Nebular Auth Logout

1.6k views Asked by At

using nebular, how can I log out with HTTP headers which contain token? just like below could be used or not?

    logout:{
      alwaysFail: false,
      endpoint: '/auth/logout',
      method: 'post',
      requireValidToken: true,
      redirect: {
        success: '/auth/login',
        failure: null,
      },
    },

waiting onling,thanks!

2

There are 2 answers

0
Shashwat Gupta On
  //  header.component.ts
    
    userMenu = [
        { title: 'Profile', icon: 'fa fa-user' },
        { title: 'Settings', icon: 'fa fa-gear' },
        { title: 'Log out', icon: 'fa fa-sign-out' }];


   // app.component.ts
    
    constructor(private menuService: NbMenuService) {  }
    
    this.menuService.onItemClick()
          .subscribe((event) => {
            this.onContecxtItemSelection(event.item.title);
          });
    
    onContecxtItemSelection(title) {
      console.log('click', title);
    
     if(title == 'Logout'){
          localStorage.clear();
        }
    }
1
saad shafiq On

you can inject the NbTokenService and clear the data with this.nbTokenService.clear(); like this:

constructor(private sidebarService: NbSidebarService
private nbTokenService:NbTokenService) {
}

logout(){
this.nbTokenService.clear()
}