Skip to content

Commit

Permalink
[ACS-8961] Emit onLogout when redirected to login page
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita-web-ua committed Dec 19, 2024
1 parent e967f20 commit d7882fe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions lib/core/src/lib/auth/guard/auth-guard.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,17 @@ describe('AuthGuardService', () => {
expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/login?redirectUrl=some-url'));
});

it('should emit onLogout if the user is NOT logged in and basic authentication is used', async () => {
spyOn(authService, 'isLoggedIn').and.returnValue(false);
spyOn(authService, 'isOauth').and.returnValue(false);
appConfigService.config.loginRoute = 'login';
spyOn(basicAlfrescoAuthService.onLogout, 'next');

await TestBed.runInInjectionContext(() => AuthGuard(route, state));

expect(basicAlfrescoAuthService.onLogout.next).toHaveBeenCalledWith(true);
});

it('should set redirect url with query params', async () => {
state.url = 'some-url;q=query';
appConfigService.config.loginRoute = 'login';
Expand Down
4 changes: 2 additions & 2 deletions lib/core/src/lib/auth/guard/auth-guard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ export class AuthGuardService {
provider: this.getProvider(),
url
});

this.basicAlfrescoAuthService.onLogout.next(true);
urlToRedirect = `${urlToRedirect}?redirectUrl=${url}`;
return this.navigate(urlToRedirect);
} else if (this.getOauthConfig().silentLogin && !this.oidcAuthenticationService.isPublicUrl()) {
const shouldPerformSsoLogin = await new Promise((resolve) => {
this.oidcAuthenticationService.shouldPerformSsoLogin$.subscribe(value => resolve(value));
this.oidcAuthenticationService.shouldPerformSsoLogin$.subscribe((value) => resolve(value));
});
if (shouldPerformSsoLogin) {
this.oidcAuthenticationService.ssoLogin(url);
Expand Down

0 comments on commit d7882fe

Please sign in to comment.