openaire-library/login/freeGuard.guard.ts

32 lines
746 B
TypeScript

import { Injectable } from '@angular/core';
import {
Router,
CanActivate,
ActivatedRouteSnapshot,
RouterStateSnapshot,
Route,
CanLoad
} from '@angular/router';
import {Observable} from 'rxjs';
import {LoginErrorCodes} from './utils/guardHelper.class';
@Injectable()
export class FreeGuard implements CanActivate {
constructor(private router: Router) {
}
check(path: string): boolean {
const valid = true;
if (!valid) {
this.router.navigate(['/user-info'], {queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': path}});
}
return valid;
}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
return this.check(state.url);
}
}