import { Injectable } from '@angular/core';
import { CanActivate, Router } from '@angular/router';
import { ToastrService } from 'ngx-toastr';
import { StorageService } from '../services/storage.service';
@Injectable({
  providedIn: 'root'
})
export class AuthGuard implements CanActivate {

  constructor(
    private router: Router, 
    private toast: ToastrService,
    private storageService: StorageService
  ) {}

  canActivate(): boolean {
    if(this.storageService.getToken()) {
      return true;
    }else{
      this.router.navigate(['/auth']);
      this.toast.error('You need to login first');
      return false;
    }
  }
}
