Below is some code I have inherited from a coworker who left. Basically the first time this component is entered, the latter half of the code is run, where it redirects to Azure B2C. After we come back from B2C login, the former part of the code should execute, but status from inProgress$ says startup where it ought to be none.
@Component({
templateUrl: './b2c-activation.component.html',
styleUrls: ['../home.scss']
})
export class B2cActivationComponent implements OnInit, OnDestroy {
private readonly b2cResetInFlowKey = 'b2cResetInFlow';
private unsubscribe$ = new Subject<void>();
private b2cResetInFlow = false;
constructor(
private oAuthAuthenticationService: OAuthAuthenticationService,
private msalService: MsalService,
private msalBroadcastService: MsalBroadcastService,
private b2CConfigurationService: B2CConfigurationService,
private route: ActivatedRoute,
private router: Router,
) {
}
ngOnInit(): void {
const sessionResetInFlow = sessionStorage.getItem(this.b2cResetInFlowKey);
this.b2cResetInFlow = sessionResetInFlow === 'true';
this.msalBroadcastService.inProgress$
.pipe(
takeUntil(this.unsubscribe$)
)
.subscribe((status) => {
if (this.b2cResetInFlow && status === InteractionStatus.None) {
this.setB2CResetInFlow(false)
this.router.navigate(['']);
}
})
const email = this.route.snapshot.queryParams.email;
const activationId = this.route.snapshot.queryParams.activationId;
this.oAuthAuthenticationService.activateB2C(email, activationId).pipe(
takeUntil(this.unsubscribe$),
).subscribe(activated => {
if (activated) {
setTimeout(() => {
this.setB2CResetInFlow(true);
const resetPasswordFlowRequest: RedirectRequest = {
authority: this.b2CConfigurationService.flowAuthorities.resetPassword,
scopes: this.b2CConfigurationService.flowAuthorities.scopes,
loginHint: email
};
this.msalService.loginRedirect(resetPasswordFlowRequest);
}, 2000)
}
});
}
private setB2CResetInFlow(inFlow: boolean) {
if (inFlow) {
sessionStorage.setItem(this.b2cResetInFlowKey, 'true');
} else {
sessionStorage.removeItem(this.b2cResetInFlowKey);
}
this.b2cResetInFlow = inFlow;
}
ngOnDestroy(): void {
this.unsubscribe$.next(null);
this.unsubscribe$.complete();
}
}
I have tried using setInterval to see if it needs time, but it keeps being in the startup state. However, when I refresh the page, the status is suddenly none.
I am looking for suggestions as to what is going wrong.