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




                                                                  

                                            




                                                                           
                                          






                                                                                
import { Injectable } from '@angular/core'
import { ActivatedRouteSnapshot, CanActivate, CanActivateChild, RouterStateSnapshot } from '@angular/router'
import { AuthService } from '../auth/auth.service'
import { RedirectService } from './redirect.service'

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

  constructor (
    private auth: AuthService,
    private redirectService: RedirectService
  ) {}

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

    this.redirectService.redirectToLogin()
    return false
  }

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