auth-guard.service.ts 546 B

12345678910111213141516171819202122232425
  1. import { AuthServiceService } from './auth-service.service';
  2. import { Injectable } from '@angular/core';
  3. import { Router, CanActivate } from '@angular/router';
  4. import { Location } from '@angular/common';
  5. @Injectable({
  6. providedIn: 'root'
  7. })
  8. export class AuthGuardService {
  9. constructor(public auth: AuthServiceService,
  10. private location: Location,
  11. public router: Router) {}
  12. canActivate(): boolean {
  13. if (this.auth.isAuthenticated()) {
  14. this.router.navigate(['/login']);
  15. return false;
  16. }
  17. return true;
  18. }
  19. }