You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
720 B
27 lines
720 B
import { Injectable } from '@angular/core';
|
|
import { CanActivate, Router } from '@angular/router';
|
|
import { LocalStorageService } from './services/localstorage.service';
|
|
import { LoginModalService } from './services/login-modal.service';
|
|
|
|
@Injectable({
|
|
providedIn: 'root',
|
|
})
|
|
export class AuthGuard implements CanActivate {
|
|
constructor(
|
|
private localStorageService: LocalStorageService,
|
|
private router: Router,
|
|
private loginModalService: LoginModalService
|
|
) {}
|
|
|
|
canActivate(): boolean {
|
|
const token = this.localStorageService.getToken();
|
|
if (token) {
|
|
return true;
|
|
} else {
|
|
this.loginModalService.openModal();
|
|
this.router.navigate(['/']);
|
|
return false;
|
|
}
|
|
}
|
|
}
|