1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-18 01:03:35 +00:00

move auth request notification to service (#8451)

- cleanup hanging promises
This commit is contained in:
Jake Fink
2024-03-28 09:34:21 -04:00
committed by GitHub
parent 37735436d1
commit bd6b3266d4
11 changed files with 57 additions and 133 deletions

View File

@@ -1,4 +1,4 @@
export abstract class AnonymousHubService {
createHubConnection: (token: string) => void;
stopHubConnection: () => void;
createHubConnection: (token: string) => Promise<void>;
stopHubConnection: () => Promise<void>;
}

View File

@@ -7,13 +7,13 @@ import {
import { MessagePackHubProtocol } from "@microsoft/signalr-protocol-msgpack";
import { firstValueFrom } from "rxjs";
import { LoginStrategyServiceAbstraction } from "../../../../auth/src/common/abstractions/login-strategy.service";
import { AuthRequestServiceAbstraction } from "../../../../auth/src/common/abstractions";
import { NotificationType } from "../../enums";
import {
AuthRequestPushNotification,
NotificationResponse,
} from "../../models/response/notification.response";
import { EnvironmentService } from "../../platform/abstractions/environment.service";
import { LogService } from "../../platform/abstractions/log.service";
import { AnonymousHubService as AnonymousHubServiceAbstraction } from "../abstractions/anonymous-hub.service";
export class AnonymousHubService implements AnonymousHubServiceAbstraction {
@@ -22,8 +22,7 @@ export class AnonymousHubService implements AnonymousHubServiceAbstraction {
constructor(
private environmentService: EnvironmentService,
private loginStrategyService: LoginStrategyServiceAbstraction,
private logService: LogService,
private authRequestService: AuthRequestServiceAbstraction,
) {}
async createHubConnection(token: string) {
@@ -37,26 +36,25 @@ export class AnonymousHubService implements AnonymousHubServiceAbstraction {
.withHubProtocol(new MessagePackHubProtocol() as IHubProtocol)
.build();
this.anonHubConnection.start().catch((error) => this.logService.error(error));
await this.anonHubConnection.start();
this.anonHubConnection.on("AuthRequestResponseRecieved", (data: any) => {
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.ProcessNotification(new NotificationResponse(data));
});
}
stopHubConnection() {
async stopHubConnection() {
if (this.anonHubConnection) {
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.anonHubConnection.stop();
await this.anonHubConnection.stop();
}
}
private async ProcessNotification(notification: NotificationResponse) {
await this.loginStrategyService.sendAuthRequestPushNotification(
notification.payload as AuthRequestPushNotification,
);
private ProcessNotification(notification: NotificationResponse) {
switch (notification.type) {
case NotificationType.AuthRequestResponse:
this.authRequestService.sendAuthRequestPushNotification(
notification.payload as AuthRequestPushNotification,
);
}
}
}