mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
refactor: CB-1093 application authentication
This commit is contained in:
@@ -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';
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
@@ -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,
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user