From: Bill Erickson Date: Thu, 28 Dec 2017 21:26:53 +0000 (-0500) Subject: LP#626157 ang2 logout/auth repairs X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=3accd21cda91edd41b95c1778cbb4c422554aaaa;p=working%2FEvergreen.git LP#626157 ang2 logout/auth repairs Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/eg2-src/src/app/staff/app.component.ts b/Open-ILS/eg2-src/src/app/staff/app.component.ts index 788edc2cb9..f4bf36fe8d 100644 --- a/Open-ILS/eg2-src/src/app/staff/app.component.ts +++ b/Open-ILS/eg2-src/src/app/staff/app.component.ts @@ -1,4 +1,4 @@ -import {Component, OnInit} from '@angular/core'; +import {Component, OnInit, NgZone} from '@angular/core'; import {Router, ActivatedRoute, NavigationEnd} from '@angular/router'; import {EgAuthService, EgAuthWsState} from '@eg/core/auth'; import {EgNetService} from '@eg/core/net'; @@ -16,6 +16,7 @@ export class EgStaffComponent implements OnInit { constructor( private router: Router, private route: ActivatedRoute, + private zone: NgZone, private net: EgNetService, private auth: EgAuthService ) {} @@ -28,7 +29,7 @@ export class EgStaffComponent implements OnInit { this.router.events.subscribe(routeEvent => { if (routeEvent instanceof NavigationEnd) { //console.debug(`EgStaffComponent routing to ${routeEvent.url}`); - this.basicAuthChecks(routeEvent); + this.basicAuthChecks(routeEvent.url); } }); @@ -41,7 +42,16 @@ export class EgStaffComponent implements OnInit { console.debug('Auth session has expired. Redirecting to login'); this.auth.redirectUrl = this.router.url; - this.router.navigate([this.loginPath]); + + // https://github.com/angular/angular/issues/18254 + // When a tab redirects to a login page as a result of + // another tab broadcasting a logout, ngOnInit() fails to + // fire in the login component, until the user interacts + // with the page. Fix it by wrapping it in zone.run(). + // This is the only navigate() where I have seen this happen. + this.zone.run(() => { + this.router.navigate([this.loginPath]); + }); }); this.route.data.subscribe((data: {staffResolver : any}) => { @@ -58,17 +68,17 @@ export class EgStaffComponent implements OnInit { * workstation, respectively, once the initial route resolvers have * done their jobs. */ - basicAuthChecks(routeEvent: NavigationEnd): void { + basicAuthChecks(url: string): void { // Access to login page is always granted - if (routeEvent.url == this.loginPath) return; + if (url == this.loginPath) return; if (!this.auth.token()) this.router.navigate([this.loginPath]); // Access to workstation admin page is granted regardless // of workstation validity. - if (routeEvent.url.indexOf(this.wsAdminBasePath) >= 0) return; + if (url.indexOf(this.wsAdminBasePath) >= 0) return; if (this.auth.workstationState != EgAuthWsState.VALID) this.router.navigate([this.wsAdminBasePath]);