unlogged-guard.service.ts 698 B

123456789101112131415161718192021222324
  1. import { Injectable } from '@angular/core'
  2. import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'
  3. import { AuthService } from '../auth/auth.service'
  4. import { RedirectService } from './redirect.service'
  5. @Injectable()
  6. export class UnloggedGuard {
  7. constructor (
  8. private auth: AuthService,
  9. private redirectService: RedirectService
  10. ) {}
  11. canActivate (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
  12. if (this.auth.isLoggedIn() === false) return true
  13. this.redirectService.redirectToHomepage()
  14. return false
  15. }
  16. canActivateChild (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
  17. return this.canActivate(route, state)
  18. }
  19. }