Ngx-admin: Logout not remove local storage token

Created on 1 Dec 2017  路  6Comments  路  Source: akveo/ngx-admin

Cause in my backend api there is no logout endpoint. My config for logout is

          logout: {
              redirect: {
                success: '/',
                failure: '/',
            },

The redirect happens but not remove the token authentication from local storage. I was forced to add manually localStorage.removeItem('auth_app_token'); in @nebular/auth/components/logout/logout.component.js

Is there a config for logout without calling backend api?
Is it causing the failure for not removing local token?

Thanks

needs investigation

Most helpful comment

@joeyjin @stat1x What I did to workaround this behaviour was create a logout component extending NbLogoutComponent and inside ngOnInit I delete the localStorage key. After that I redirect to login.

import { Component, OnInit } from '@angular/core';
import { NbLogoutComponent } from '@nebular/auth';

@Component({
  selector: 'logout',
  templateUrl: './logout.component.html',
  styleUrls: ['./logout.component.scss']
})
export class LogoutComponent extends NbLogoutComponent implements OnInit {

  ngOnInit(){
    localStorage.removeItem('auth_app_token');

    this.router.navigateByUrl('/auth/login');
  }

}

All 6 comments

Having the same issue. Fails on redirect ReturnUrl

I have the same issue. What should the API return as a response?

Logout doesn't work because redirect is null.

@robertoAg if I put localStorage.removeItem('auth_app_token'); in logout.js which is ok BUT it's not redirect to login page. If I put localStorage.removeItem('auth_app_token'); in login.js and have userMenu = [{ title: 'Profile' }, { title: 'Log out' , link: '/auth/login'}]; in hearder.component.ts page.... it redirect to login page but not execute localStorage.removeItem('auth_app_token') unless you refresh it..how did you resolve this? Thanks!

Same here.

@joeyjin @stat1x What I did to workaround this behaviour was create a logout component extending NbLogoutComponent and inside ngOnInit I delete the localStorage key. After that I redirect to login.

import { Component, OnInit } from '@angular/core';
import { NbLogoutComponent } from '@nebular/auth';

@Component({
  selector: 'logout',
  templateUrl: './logout.component.html',
  styleUrls: ['./logout.component.scss']
})
export class LogoutComponent extends NbLogoutComponent implements OnInit {

  ngOnInit(){
    localStorage.removeItem('auth_app_token');

    this.router.navigateByUrl('/auth/login');
  }

}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

burtonator picture burtonator  路  3Comments

igorls picture igorls  路  3Comments

lopn picture lopn  路  4Comments

Kalaijagdai picture Kalaijagdai  路  4Comments

tal-shahar picture tal-shahar  路  3Comments