Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit dd9ddef

Browse files
committed
responded to feedback
1 parent 712a454 commit dd9ddef

File tree

3 files changed

+39
-17
lines changed

3 files changed

+39
-17
lines changed

2-Authorization-I/1-call-graph/SPA/src/app/account-switch/account-switch.component.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,16 @@ export class AccountSwitchComponent implements OnInit {
2929

3030
switchAccount(account: AccountInfo | null) {
3131
const activeAccount = this.authService.instance.getActiveAccount();
32+
this.authService.instance.setActiveAccount(account);
3233
if (!account) {
33-
this.authService.instance.setActiveAccount(account);
3434
this.authService.instance.loginRedirect({
3535
...this.msalGuardConfig.authRequest,
3636
prompt: 'login',
3737
} as RedirectRequest);
3838
} else if (
3939
account &&
40-
activeAccount?.homeAccountId != account.homeAccountId
40+
activeAccount?.homeAccountId !== account.homeAccountId
4141
) {
42-
this.authService.instance.setActiveAccount(account);
4342
this.authService.instance
4443
.ssoSilent({
4544
...this.msalGuardConfig.authRequest,

2-Authorization-I/1-call-graph/SPA/src/app/app.component.ts

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import { Component, OnInit, Inject, OnDestroy } from '@angular/core';
2-
import { MsalService, MsalBroadcastService, MSAL_GUARD_CONFIG, MsalGuardConfiguration } from '@azure/msal-angular';
2+
import {
3+
MsalService,
4+
MsalBroadcastService,
5+
MSAL_GUARD_CONFIG,
6+
MsalGuardConfiguration,
7+
} from '@azure/msal-angular';
38
import {
49
AuthenticationResult,
510
InteractionStatus,
611
InteractionType,
712
PopupRequest,
813
RedirectRequest,
914
AccountInfo,
15+
EventMessage,
16+
EventType
1017
} from '@azure/msal-browser';
1118
import { Subject } from 'rxjs';
1219
import { filter, takeUntil } from 'rxjs/operators';
@@ -55,6 +62,31 @@ export class AppComponent implements OnInit, OnDestroy {
5562
this.setLoginDisplay();
5663
this.checkAndSetActiveAccount();
5764
});
65+
66+
this.msalBroadcastService.msalSubject$
67+
.pipe(
68+
filter(
69+
(msg: EventMessage) => msg.eventType === EventType.LOGOUT_SUCCESS
70+
),
71+
takeUntil(this._destroying$)
72+
)
73+
.subscribe((result: EventMessage) => {
74+
this.setLoginDisplay();
75+
this.checkAndSetActiveAccount();
76+
});
77+
78+
79+
this.msalBroadcastService.msalSubject$
80+
.pipe(
81+
filter(
82+
(msg: EventMessage) => msg.eventType === EventType.LOGIN_SUCCESS
83+
),
84+
takeUntil(this._destroying$)
85+
)
86+
.subscribe((result: EventMessage) => {
87+
const payload = result.payload as AuthenticationResult;
88+
this.authService.instance.setActiveAccount(payload.account);
89+
});
5890
}
5991

6092
setLoginDisplay() {
@@ -124,7 +156,9 @@ export class AppComponent implements OnInit, OnDestroy {
124156

125157
logout() {
126158
clearStorage(this.authService.instance.getActiveAccount());
127-
this.authService.logout();
159+
this.authService.logout({
160+
account: this.authService.instance.getActiveAccount(),
161+
});
128162
}
129163

130164
// unsubscribe to events when component is destroyed

2-Authorization-I/1-call-graph/SPA/src/app/home/home.component.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,7 @@ export class HomeComponent implements OnInit {
3030
) {}
3131

3232
ngOnInit(): void {
33-
this.msalBroadcastService.msalSubject$
34-
.pipe(
35-
filter(
36-
(msg: EventMessage) => msg.eventType === EventType.LOGIN_SUCCESS
37-
),
38-
takeUntil(this._destroying$)
39-
)
40-
.subscribe((result: EventMessage) => {
41-
const payload = result.payload as AuthenticationResult;
42-
this.authService.instance.setActiveAccount(payload.account);
43-
});
44-
33+
4534
this.msalBroadcastService.inProgress$
4635
.pipe(
4736
filter((status: InteractionStatus) => status === InteractionStatus.None)

0 commit comments

Comments
 (0)