Skip to content

Commit

Permalink
refactor: CB-1093 application authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
Wroud committed Jul 13, 2021
1 parent a0f22be commit 8652e1c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 6 additions & 0 deletions webapp/packages/core-routing/src/Screen/ScreenService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import type { SubscribeState } from 'router5';

import { injectable } from '@cloudbeaver/core-di';
import { Executor, IExecutor } from '@cloudbeaver/core-executor';

import { RouterService } from '../RouterService';
import type { IScreen, ScreenRoute } from './IScreen';
Expand All @@ -19,12 +20,15 @@ export class ScreenService {
return this.getScreenByRoute(this.routerService.route);
}

readonly routeChange: IExecutor;

private screens = new Map<string, IScreen>();
private routeScreenMap = new Map<string, string>();

constructor(
readonly routerService: RouterService
) {
this.routeChange = new Executor();
this.routerService.subscribe(this.onRouteChange.bind(this));
}

Expand Down Expand Up @@ -82,6 +86,8 @@ export class ScreenService {
}

private async onRouteChange(state: SubscribeState) {
await this.routeChange.execute();

if (state.previousRoute) {
await this.getScreenByRoute(state.previousRoute.name)?.onDeactivate?.(state.previousRoute, state.route);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

import { AdministrationScreenService } from '@cloudbeaver/core-administration';
import { AppScreenService } from '@cloudbeaver/core-app';
import { AppAuthService, AuthProviderContext, AuthProviderService, AuthProvidersResource, AUTH_PROVIDER_LOCAL_ID, UserInfoResource } from '@cloudbeaver/core-authentication';
import { injectable, Bootstrap } from '@cloudbeaver/core-di';
import { NotificationService } from '@cloudbeaver/core-events';
Expand All @@ -23,7 +22,6 @@ export class AuthenticationService extends Bootstrap {
private authPromise: Promise<void> | null;
constructor(
private screenService: ScreenService,
private appScreenService: AppScreenService,
private appAuthService: AppAuthService,
private authDialogService: AuthDialogService,
private userInfoResource: UserInfoResource,
Expand Down Expand Up @@ -79,8 +77,8 @@ export class AuthenticationService extends Bootstrap {
ExecutorInterrupter.interrupter(() => this.appAuthService.isAuthNeeded())
);
this.sessionDataResource.beforeLoad.addPostHandler(() => { this.requireAuthentication(); });
this.screenService.routeChange.addHandler(() => this.requireAuthentication());

this.appScreenService.activation.addHandler(() => this.requireAuthentication());
this.administrationScreenService.ensurePermissions.addHandler(async () => {
const userInfo = await this.userInfoResource.load();
if (userInfo) {
Expand Down

0 comments on commit 8652e1c

Please sign in to comment.