auth.guard.ts 762 Bytes
Newer Older
1
2
3
import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router } from '@angular/router';
import { Observable } from 'rxjs/Observable';
4
import { TranslateService } from '@ngx-translate/core';
5
6
7

@Injectable()
export class AuthGuard implements CanActivate {
8
  translateService: any;
9

10
11
	constructor(private router: Router, public translate: TranslateService){
    this.translateService = translate;
12
13
14
15
16
17
18
	}

  canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean {
    
    if(sessionStorage.getItem('currentUser')){
    	return true;
    }
19
    this.router.navigate(['/'+this.translateService.get('i18n.code').value+'/login']);
20
21
22
    return false;
  }
}