Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Injectable } from '@angular/core';
- import { Location } from '@angular/common';
- import { CanActivate, RouterStateSnapshot, ActivatedRouteSnapshot } from '@angular/router';
- import { EidCookieService } from '../services/eid/eIdCookie.service';
- import URL = require('url-parse');
- import { Document } from '../components/document/document';
- @Injectable()
- export class EidGuard implements CanActivate {
- constructor(private eIdCookieService: EidCookieService, private location: Location) { }
- private getEidLoginRedirectUrl(currentUrl) {
- const protocol = new URL(currentUrl).protocol;
- switch (process.env.NODE_ENV) {
- case 'PROD':
- case 'production':
- case 'build':
- return `http://sso-portal.xxxxxxx.com`;
- case 'TEST':
- case 'testing':
- return `http://sso-portal-test.xxxxxxx.com`;
- default:
- return `http://sso-portal-dev.xxxxxxx.com`;
- }
- }
- canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
- if (!this.eIdCookieService.checkCookie(('auth-cookie'))) {
- const redirectUrl = this.getEidLoginRedirectUrl(state.url);
- this.location.go(redirectUrl);
- return false;
- }
- return true;
- }
- canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
- return this.canActivate(route, state);
- }
- }
Add Comment
Please, Sign In to add comment