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



                                                    
                            

               














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

@Injectable()
export class UnloggedGuard {

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

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

    this.redirectService.redirectToHomepage()
    return false
  }

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