import {Component, OnInit} from '@angular/core';
import {AccountService} from "../../services/account.service";
import {Router} from "@angular/router";

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

  constructor(
    private accountService: AccountService,
    private router: Router
  ) {
  }

  ngOnInit(): void {
    if (!this.accountService.isLoggedIn()) {
      this.router.navigate(['/account/login'])
    }

    this.accountService.logout(() => {
      this.router.navigate(['/account/login'])
    })
  }

}
