openaire-library/login/freeGuard.guard.ts

30 lines
727 B
TypeScript
Raw Normal View History

import { Injectable } from '@angular/core';
import {
Router,
CanActivate,
ActivatedRouteSnapshot,
RouterStateSnapshot,
} 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);
}
}