From 6ec661254c9a51482f9ac25b44f21aa0eeff8e4a Mon Sep 17 00:00:00 2001 From: Patrick Sun Date: Sat, 8 May 2021 02:22:04 +1000 Subject: [PATCH] if another tab from the same browser logged in as a different user, we logout others. --- src/app/app.component.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 88900f9..fdfebaf 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,13 +1,12 @@ import { Component, OnDestroy, OnInit, ViewChild, ViewEncapsulation } from '@angular/core'; import { Subscription } from 'rxjs'; import { LoanEditComponent } from './loan-edit/loan-edit.component'; - import { AuthService } from './service/auth.service'; import { MenuService } from './service/menu.service'; - import {WebSocketService} from './websocket'; -import {AppConfig} from './app.config'; import {Title} from '@angular/platform-browser'; +import {WsLoginEventModel} from './models/websocket/ws.login.event.model'; +import {SessionService} from './service/session.service'; @Component({ selector: 'app-root', @@ -25,7 +24,7 @@ export class AppComponent implements OnInit , OnDestroy { constructor(private menuService: MenuService, private authService: AuthService, - private config: AppConfig, + private ss: SessionService, private wsService: WebSocketService, private titleService: Title){ this.webSocketSubscription = wsService.subscribe(m => { @@ -33,7 +32,7 @@ export class AppComponent implements OnInit , OnDestroy { }); this.wsLoginSub = this.wsService.LoginEvent.subscribe( m => { - console.log('login event ', m); + this.onWSLogin(m); }); this.titleService.setTitle(this.title); @@ -48,15 +47,12 @@ export class AppComponent implements OnInit , OnDestroy { listenToMenuEvent(): void { this.menuItemSub = this.menuService.itemClicked.subscribe( - (item:any) =>{ + (item: any) => { // console.log("emit on select : " + item.text); if ( item.popup === 'loanEdit'){ -// this.loanEdit.somedata = '' + Math.random() + 'changed'; -// this.loanEdit.open('dialog'); } } ); - } ngOnDestroy(): void { @@ -64,4 +60,12 @@ export class AppComponent implements OnInit , OnDestroy { this.wsLoginSub.unsubscribe(); } + onWSLogin(e: WsLoginEventModel): void { + if ( e.Mid === this.ss.loggedIn.machineId && e.Sid === this.ss.loggedIn.session ){ + if ( e.Uid !== this.ss.loggedIn.User.Id && e.Uid !== '') { + this.ss.logout(); + } + } + } + }