diff --git a/claims/claimsAdmin/claimsAdmin.component.ts b/claims/claimsAdmin/claimsAdmin.component.ts index 6af4d320..e35f0f96 100644 --- a/claims/claimsAdmin/claimsAdmin.component.ts +++ b/claims/claimsAdmin/claimsAdmin.component.ts @@ -58,8 +58,10 @@ export class ClaimsAdminComponent { } ngOnInit() { - this.userManagementService.getUserInfo(this.userInfoURL).subscribe(user => { - this.user = user; - }); + if (typeof document !== 'undefined') { + this.userManagementService.getUserInfo(this.userInfoURL).subscribe(user => { + this.user = user; + }); + } } } diff --git a/connect/communityGuard/connectAdminLoginGuard.guard.ts b/connect/communityGuard/connectAdminLoginGuard.guard.ts index 12948ef4..07426edf 100644 --- a/connect/communityGuard/connectAdminLoginGuard.guard.ts +++ b/connect/communityGuard/connectAdminLoginGuard.guard.ts @@ -28,7 +28,7 @@ export class ConnectAdminLoginGuard implements CanActivate, CanLoad { let errorCode = LoginErrorCodes.NOT_LOGIN; let email = null; const authorized = this.propertiesService.subscribeEnvironment().pipe(map(res => res), mergeMap(properties => { - return this.userManagementService.getUserInfo(properties.userInfoUrl).pipe(map(user => { + return typeof document !== 'undefined' && this.userManagementService.getUserInfo(properties.userInfoUrl).pipe(map(user => { if (user) { email = user.email; if (Session.isPortalAdministrator(user) || Session.isCommunityCurator(user)) { diff --git a/connect/communityGuard/connectSubscriber.guard.ts b/connect/communityGuard/connectSubscriber.guard.ts index d2e48b8b..58d6e6c5 100644 --- a/connect/communityGuard/connectSubscriber.guard.ts +++ b/connect/communityGuard/connectSubscriber.guard.ts @@ -21,7 +21,7 @@ export class ConnectSubscriberGuard implements CanActivate { let errorCode = LoginErrorCodes.NOT_LOGIN; let email = null; const subscribed = this.propertiesService.subscribeEnvironment().pipe(map(res => res), mergeMap(properties => { - return this.userManagementService.getUserInfo(properties.userInfoUrl).pipe(map(user => { + return typeof document !== 'undefined' && this.userManagementService.getUserInfo(properties.userInfoUrl).pipe(map(user => { if (user) { errorCode = LoginErrorCodes.NOT_SUBSCRIBER; email = user.email; diff --git a/connect/communityGuard/isCommunityOrAdmin.ts b/connect/communityGuard/isCommunityOrAdmin.ts index 4589a140..d3d04d4e 100644 --- a/connect/communityGuard/isCommunityOrAdmin.ts +++ b/connect/communityGuard/isCommunityOrAdmin.ts @@ -19,7 +19,7 @@ export class IsCommunityOrAdmin implements CanActivate { return true; } else { const obs = this.propertiesService.subscribeEnvironment().pipe(mergeMap(properties => { - return this.userManagementService.getUserInfo(properties['userInfoUrl']).pipe(map(user => { + return typeof document !== 'undefined' && this.userManagementService.getUserInfo(properties['userInfoUrl']).pipe(map(user => { return Session.isPortalAdministrator(user); })); })); diff --git a/login/adminLoginGuard.guard.ts b/login/adminLoginGuard.guard.ts index 2118b75c..fe74b5a9 100644 --- a/login/adminLoginGuard.guard.ts +++ b/login/adminLoginGuard.guard.ts @@ -26,7 +26,7 @@ export class AdminLoginGuard implements CanActivate{ check(path: string): Observable { let errorCode = LoginErrorCodes.NOT_LOGIN; const obs = this.propertiesService.subscribeEnvironment().pipe(mergeMap(properties => { - return this.userManagementService.getUserInfo(properties['userInfoUrl']).pipe(map( user => { + return typeof document !== 'undefined' && this.userManagementService.getUserInfo(properties['userInfoUrl']).pipe(map( user => { if(user) { errorCode = LoginErrorCodes.NOT_ADMIN; } diff --git a/login/claimsCuratorGuard.guard.ts b/login/claimsCuratorGuard.guard.ts index c59cf6dd..3e282c57 100644 --- a/login/claimsCuratorGuard.guard.ts +++ b/login/claimsCuratorGuard.guard.ts @@ -26,7 +26,7 @@ export class ClaimsCuratorGuard implements CanActivate { check(path: string): Observable |boolean { let errorCode = LoginErrorCodes.NOT_LOGIN; const obs = this.propertiesService.subscribeEnvironment().pipe(mergeMap(properties => { - return this.userManagementService.getUserInfo(properties['userInfoUrl']).pipe(map( user => { + return typeof document !== 'undefined' && this.userManagementService.getUserInfo(properties['userInfoUrl']).pipe(map( user => { if(user) { errorCode = LoginErrorCodes.NOT_ADMIN; } diff --git a/login/user.component.ts b/login/user.component.ts index 44e23177..4dbc5a73 100644 --- a/login/user.component.ts +++ b/login/user.component.ts @@ -47,22 +47,23 @@ export class UserComponent { }); if (typeof document !== 'undefined') { this.server = false; - } - this.userManagementsService.getUserInfo(this.properties.userInfoUrl).subscribe(user => { - this.user = user; - this.loggedIn = !!this.user; - this.errorMessage = ""; - this.sub = this.route.queryParams.subscribe(params => { - this.errorCode = params["errorCode"]; - this.redirectUrl = params["redirectUrl"]; + this.userManagementsService.getUserInfo(this.properties.userInfoUrl).subscribe(user => { + this.user = user; + this.loggedIn = !!this.user; this.errorMessage = ""; - if (this.loggedIn && this.errorCode == '1') { - this.redirect(); - } + this.sub = this.route.queryParams.subscribe(params => { + this.errorCode = params["errorCode"]; + this.redirectUrl = params["redirectUrl"]; + this.errorMessage = ""; + if (this.loggedIn && this.errorCode == '1') { + this.redirect(); + } + }); }); - }); + } } + ngOnDestroy() { this.sub.unsubscribe(); if (this.sublogin) { diff --git a/services/user-management.service.ts b/services/user-management.service.ts index 047fef69..a4932ac9 100644 --- a/services/user-management.service.ts +++ b/services/user-management.service.ts @@ -2,7 +2,7 @@ import {Injectable} from '@angular/core'; import {HttpClient} from '@angular/common/http'; import {Observable, of} from "rxjs"; import {COOKIE, User} from "../login/utils/helper.class"; -import {catchError, map} from "rxjs/operators"; +import {catchError, map, timeout} from "rxjs/operators"; @Injectable({ providedIn: 'root' @@ -16,7 +16,7 @@ export class UserManagementService { const token = COOKIE.getCookie('AccessToken'); return this.http.get(url + token).pipe(map(userInfo => { return this.parseUserInfo(userInfo); - })).pipe(catchError(() => { + })).pipe(timeout(2000), catchError(() => { return of(null); })); }