CB-3135 fix: auth dialog appearance (#1697)

This commit is contained in:
Alexey
2023-05-27 17:50:06 +03:00
committed by GitHub
parent 52c171f4dc
commit c8c7307abf
2 changed files with 46 additions and 11 deletions
@@ -126,14 +126,14 @@ export class AuthenticationService extends Bootstrap {
}
private async auth(persistent: boolean, options: IAuthOptions) {
const contexts = await this.onLogin.execute('before');
if (ExecutorInterrupter.isInterrupted(contexts)) {
if (this.authPromise) {
await this.waitAuth();
return;
}
if (this.authPromise) {
await this.authPromise;
const contexts = await this.onLogin.execute('before');
if (ExecutorInterrupter.isInterrupted(contexts)) {
return;
}
@@ -170,6 +170,8 @@ export class AuthenticationService extends Bootstrap {
}
private async requireAuthentication() {
await this.waitAuth();
const authNeeded = await this.appAuthService.isAuthNeeded();
if (!authNeeded) {
return;
@@ -188,6 +190,8 @@ export class AuthenticationService extends Bootstrap {
this.screenService.routeChange.addHandler(() => this.requireAuthentication());
this.administrationScreenService.ensurePermissions.addHandler(async () => {
await this.waitAuth();
const userInfo = await this.userInfoResource.load();
if (userInfo) {
return;
@@ -209,14 +213,16 @@ export class AuthenticationService extends Bootstrap {
if (isAutoLoginSessionAction(data)) {
const user = await this.userInfoResource.finishFederatedAuthentication(data['auth-id'], false);
if (user && this.authPromise) {
this.authDialogService.closeLoginForm(this.authPromise);
if (user) {
this.authDialogService.closeLoginForm();
}
action.process();
}
}
private readonly requestAuthProviderHandler: IExecutorHandler<RequestedProvider> = async (data, contexts) => {
await this.waitAuth();
if (data.providerId === AUTH_PROVIDER_LOCAL_ID) {
const provider = contexts.getContext(AuthProviderContext);
provider.auth();
@@ -239,4 +245,10 @@ export class AuthenticationService extends Bootstrap {
provider.auth();
}
};
private async waitAuth() {
try {
await this.authPromise;
} catch {}
}
}
@@ -14,9 +14,19 @@ import { AuthDialog } from './AuthDialog';
@injectable()
export class AuthDialogService {
get isPersistent(): boolean {
return this.persistent;
}
private persistent: boolean;
private dialog: Promise<DialogueStateResult | null> | null;
constructor(
private readonly commonDialogService: CommonDialogService
) { }
) {
this.persistent = false;
this.dialog = null;
}
showLoginForm(
persistent = false,
@@ -24,10 +34,23 @@ export class AuthDialogService {
providerId: null,
}
): Promise<DialogueStateResult | null> {
return this.commonDialogService.open(AuthDialog, options, { persistent });
if (this.dialog) {
return this.dialog;
}
this.persistent = persistent;
this.dialog = this.commonDialogService.open(AuthDialog, options, { persistent });
this.dialog.finally(() => {
this.dialog = null;
this.persistent = false;
});
return this.dialog;
}
closeLoginForm(promise: Promise<DialogueStateResult | null>): void {
this.commonDialogService.rejectDialog(promise);
closeLoginForm(): void {
if (this.dialog) {
this.commonDialogService.rejectDialog(this.dialog);
}
}
}