Skip to content

Instantly share code, notes, and snippets.

@NyaGarcia
Created November 30, 2021 14:48
Show Gist options
  • Save NyaGarcia/298654cd9c7c93f1c8f2af4d8cce0ca6 to your computer and use it in GitHub Desktop.
Save NyaGarcia/298654cd9c7c93f1c8f2af4d8cce0ca6 to your computer and use it in GitHub Desktop.
Adding a logout method to the dashboard
import { Component, OnInit } from '@angular/core';
import { AuthService } from '../../core/services/auth.service';
import { Router } from '@angular/router';
@Component({
selector: 'app-dashboard',
templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.css'],
})
export class DashboardComponent implements OnInit {
constructor(private authService: AuthService, private router: Router) {}
ngOnInit(): void {}
logout() {
this.authService
.logout()
.then(() => this.router.navigate(['/']))
.catch((e) => console.log(e.message));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment