aboutsummaryrefslogblamecommitdiffhomepage
path: root/client/src/app/core/routing/login-guard.service.ts
blob: 7b1c37ee8929976022d60ff1592d4ef9fcf28e58 (plain) (tree)
1
2
3
4
                                          
                                                                                                                    
 
                                                  



















                                                                                
import { Injectable } from '@angular/core'
import { ActivatedRouteSnapshot, CanActivate, CanActivateChild, Router, RouterStateSnapshot } from '@angular/router'

import { AuthService } from '../auth/auth.service'

@Injectable()
export class LoginGuard implements CanActivate, CanActivateChild {

  constructor (
    private router: Router,
    private auth: AuthService
  ) {}

  canActivate (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
    if (this.auth.isLoggedIn() === true) return true

    this.router.navigate([ '/login' ])
    return false
  }

  canActivateChild (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
    return this.canActivate(route, state)
  }
}