How do I log out at Angular 4?

Asked

Viewed 368 times

-1

good afternoon, I would like to know how to log out in angular 4, because I am developing a Dashboard and only this requirement is missing Thanks in advance.

 import { Component, Input, OnInit } from '@angular/core';

import { NbMenuService, NbSidebarService } from '@nebular/theme';
import { UserService } from '../../../@core/data/users.service';
import { AnalyticsService } from '../../../@core/utils/analytics.service';

@Component({
  selector: 'ngx-header',
  styleUrls: ['./header.component.scss'],
  templateUrl: './header.component.html',
})
export class HeaderComponent implements OnInit {


  @Input() position = 'normal';

  user: any;

  userMenu = [{ title: 'Profile' }, { title: 'Log out' }];

  constructor(private sidebarService: NbSidebarService,
              private menuService: NbMenuService,
              private userService: UserService,
              private analyticsService: AnalyticsService) {
  }

  ngOnInit() {
    this.userService.getUsers()
      .subscribe((users: any) => this.user = users.nick);
  }

  toggleSidebar(): boolean {
    this.sidebarService.toggle(true, 'menu-sidebar');
    return false;
  }

  toggleSettings(): boolean {
    this.sidebarService.toggle(false, 'settings-sidebar');
    return false;
  }

  goToHome() {
    this.menuService.navigateHome();
  }

  startSearch() {
    this.analyticsService.trackEvent('startSearch');
  }
}

2 answers

0

There should be a route in your api to perform this man action. You can reset the user and password in Angular, or delete the verification token, this would solve your problem, but a route would be the most indicated.

0

Good morning, this will depend on how you are logging in ... if it is with cookie or localstorage, a component can be created, where you could just use the method to clean up by Typescript and redirect, if you are doing this via server, would have to make a method in your application and call an httprequest ... explain how is your application.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.