diff --git a/projects/angular-auth-oidc-client/src/lib/auth-state/check-auth.service.spec.ts b/projects/angular-auth-oidc-client/src/lib/auth-state/check-auth.service.spec.ts index df28d48c..d7f95345 100644 --- a/projects/angular-auth-oidc-client/src/lib/auth-state/check-auth.service.spec.ts +++ b/projects/angular-auth-oidc-client/src/lib/auth-state/check-auth.service.spec.ts @@ -608,6 +608,28 @@ describe('CheckAuthService', () => { ]); }); })); + + it('fires CheckingAuth-Event on start and finished event on end if not authenticated', waitForAsync(() => { + const allConfigs = [ + { configId: 'configId1', authority: 'some-authority' }, + ]; + + spyOn(currentUrlService, 'getCurrentUrl').and.returnValue( + 'http://localhost:4200' + ); + spyOn(authStateService, 'areAuthStorageTokensValid').and.returnValue( + false + ); + + const fireEventSpy = spyOn(publicEventsService, 'fireEvent'); + + checkAuthService.checkAuth(allConfigs[0], allConfigs).subscribe(() => { + expect(fireEventSpy.calls.allArgs()).toEqual([ + [EventTypes.CheckingAuth], + [EventTypes.CheckingAuthFinished], + ]); + }); + })); }); describe('checkAuthIncludingServer', () => { diff --git a/projects/angular-auth-oidc-client/src/lib/auth-state/check-auth.service.ts b/projects/angular-auth-oidc-client/src/lib/auth-state/check-auth.service.ts index 7fee5de5..30a71ab2 100644 --- a/projects/angular-auth-oidc-client/src/lib/auth-state/check-auth.service.ts +++ b/projects/angular-auth-oidc-client/src/lib/auth-state/check-auth.service.ts @@ -257,9 +257,8 @@ export class CheckAuthService { this.authStateService.setAuthenticatedAndFireEvent(allConfigs); this.userService.publishUserDataIfExists(config, allConfigs); } - - this.publicEventsService.fireEvent(EventTypes.CheckingAuthFinished); } + this.publicEventsService.fireEvent(EventTypes.CheckingAuthFinished); const result: LoginResponse = { isAuthenticated,