import { Component, OnInit, SecurityContext } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { DataService } from './common/services/data.service'; import { DomSanitizer, SafeResourceUrl, SafeUrl, } from '@angular/platform-browser'; import { TokenService } from './common/services/token.service'; import { forkJoin } from 'rxjs'; import { CommonService } from './common/services/common.service'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.scss'], }) export class AppComponent implements OnInit { title = 'votools'; navMenu: string; miliSecDay: number = 60000; isUnauthorized: boolean = false; constructor( private activatedRoute: ActivatedRoute, private dataService: DataService, private tokenService: TokenService, private router: Router, private commonService: CommonService ) { this.isUnauthorized = false; this.activatedRoute.queryParams.subscribe((params) => { if (params['param1'] != null) { let user = this.commonService.doDecrypt(params['param1'].trim()); forkJoin(this.tokenService.getToken()).subscribe(t => { sessionStorage.setItem('token', t[0].token_type + ' ' + t[0].access_token); this.commonService.getUserInfo(user.trim()).subscribe(v => { if (v && v.length > 0) { this.isUnauthorized = false; sessionStorage.setItem('email', user); if (params['param2'] != null) { let route = this.commonService.doDecrypt(params['param2'].trim()); this.navMenu = route; } this.onLoad(); } else { this.isUnauthorized = false; this.router.navigateByUrl('/unauthorized', { skipLocationChange: true, }); } }); }); } else { this.refreshToken(); if (params['param2'] != null) { let route = this.commonService.doDecrypt(params['param2'].trim()); this.navMenu = route; } this.onLoad(); } }); } refreshToken() { console.log(' token refresh---->>'); forkJoin(this.tokenService.getToken()).subscribe(t => { debugger; sessionStorage.setItem('token', t[0].token_type + ' ' + t[0].access_token); }); } onLoad() { const email = sessionStorage.getItem('email'); if (this.navMenu === 'Settings') { this.router.navigateByUrl('/settings/core-value', { skipLocationChange: true, }); this.dataService.getEmail(email); } else if (this.navMenu === 'Goals') { this.router.navigateByUrl('/goals/goal-plan-inventory', { skipLocationChange: true }); this.dataService.getEmail(email); } else if (this.navMenu === 'PerformanceManagement') { this.router.navigateByUrl('/performance-management/rating-scale', { skipLocationChange: true }); this.dataService.getEmail(email); } } ngOnInit(): void { } }