Add LoginSuccessHandlerService
This commit is contained in:
parent
112a2398a7
commit
77b525cbf1
|
@ -35,6 +35,8 @@ import {
|
||||||
RegisterRouteService,
|
RegisterRouteService,
|
||||||
AuthRequestApiService,
|
AuthRequestApiService,
|
||||||
DefaultAuthRequestApiService,
|
DefaultAuthRequestApiService,
|
||||||
|
DefaultLoginSuccessHandlerService,
|
||||||
|
LoginSuccessHandlerService,
|
||||||
} from "@bitwarden/auth/common";
|
} from "@bitwarden/auth/common";
|
||||||
import { ApiService as ApiServiceAbstraction } from "@bitwarden/common/abstractions/api.service";
|
import { ApiService as ApiServiceAbstraction } from "@bitwarden/common/abstractions/api.service";
|
||||||
import { AuditService as AuditServiceAbstraction } from "@bitwarden/common/abstractions/audit.service";
|
import { AuditService as AuditServiceAbstraction } from "@bitwarden/common/abstractions/audit.service";
|
||||||
|
@ -1413,6 +1415,11 @@ const safeProviders: SafeProvider[] = [
|
||||||
ConfigService,
|
ConfigService,
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
|
safeProvider({
|
||||||
|
provide: LoginSuccessHandlerService,
|
||||||
|
useClass: DefaultLoginSuccessHandlerService,
|
||||||
|
deps: [SyncService, UserAsymmetricKeysRegenerationService],
|
||||||
|
}),
|
||||||
];
|
];
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
|
|
|
@ -10,6 +10,7 @@ import {
|
||||||
AuthRequestServiceAbstraction,
|
AuthRequestServiceAbstraction,
|
||||||
LoginEmailServiceAbstraction,
|
LoginEmailServiceAbstraction,
|
||||||
LoginStrategyServiceAbstraction,
|
LoginStrategyServiceAbstraction,
|
||||||
|
LoginSuccessHandlerService,
|
||||||
} from "@bitwarden/auth/common";
|
} from "@bitwarden/auth/common";
|
||||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
import { AnonymousHubService } from "@bitwarden/common/auth/abstractions/anonymous-hub.service";
|
import { AnonymousHubService } from "@bitwarden/common/auth/abstractions/anonymous-hub.service";
|
||||||
|
@ -32,7 +33,6 @@ import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/pl
|
||||||
import { ValidationService } from "@bitwarden/common/platform/abstractions/validation.service";
|
import { ValidationService } from "@bitwarden/common/platform/abstractions/validation.service";
|
||||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||||
import { UserId } from "@bitwarden/common/types/guid";
|
import { UserId } from "@bitwarden/common/types/guid";
|
||||||
import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction";
|
|
||||||
import { ButtonModule, LinkModule, ToastService } from "@bitwarden/components";
|
import { ButtonModule, LinkModule, ToastService } from "@bitwarden/components";
|
||||||
import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy";
|
import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy";
|
||||||
|
|
||||||
|
@ -86,9 +86,9 @@ export class LoginViaAuthRequestComponent implements OnInit, OnDestroy {
|
||||||
private passwordGenerationService: PasswordGenerationServiceAbstraction,
|
private passwordGenerationService: PasswordGenerationServiceAbstraction,
|
||||||
private platformUtilsService: PlatformUtilsService,
|
private platformUtilsService: PlatformUtilsService,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private syncService: SyncService,
|
|
||||||
private toastService: ToastService,
|
private toastService: ToastService,
|
||||||
private validationService: ValidationService,
|
private validationService: ValidationService,
|
||||||
|
private loginSuccessHandlerService: LoginSuccessHandlerService,
|
||||||
) {
|
) {
|
||||||
this.clientType = this.platformUtilsService.getClientType();
|
this.clientType = this.platformUtilsService.getClientType();
|
||||||
|
|
||||||
|
@ -483,7 +483,7 @@ export class LoginViaAuthRequestComponent implements OnInit, OnDestroy {
|
||||||
const activeAccount = await firstValueFrom(this.accountService.activeAccount$);
|
const activeAccount = await firstValueFrom(this.accountService.activeAccount$);
|
||||||
await this.deviceTrustService.trustDeviceIfRequired(activeAccount.id);
|
await this.deviceTrustService.trustDeviceIfRequired(activeAccount.id);
|
||||||
|
|
||||||
await this.handleSuccessfulLoginNavigation();
|
await this.handleSuccessfulLoginNavigation(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -553,17 +553,17 @@ export class LoginViaAuthRequestComponent implements OnInit, OnDestroy {
|
||||||
} else if (loginResponse.forcePasswordReset != ForceSetPasswordReason.None) {
|
} else if (loginResponse.forcePasswordReset != ForceSetPasswordReason.None) {
|
||||||
await this.router.navigate(["update-temp-password"]);
|
await this.router.navigate(["update-temp-password"]);
|
||||||
} else {
|
} else {
|
||||||
await this.handleSuccessfulLoginNavigation();
|
await this.handleSuccessfulLoginNavigation(loginResponse.userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleSuccessfulLoginNavigation() {
|
private async handleSuccessfulLoginNavigation(userId: UserId) {
|
||||||
if (this.flow === Flow.StandardAuthRequest) {
|
if (this.flow === Flow.StandardAuthRequest) {
|
||||||
// Only need to set remembered email on standard login with auth req flow
|
// Only need to set remembered email on standard login with auth req flow
|
||||||
await this.loginEmailService.saveEmailSettings();
|
await this.loginEmailService.saveEmailSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.syncService.fullSync(true);
|
await this.loginSuccessHandlerService.run(userId);
|
||||||
await this.router.navigate(["vault"]);
|
await this.router.navigate(["vault"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import { JslibModule } from "@bitwarden/angular/jslib.module";
|
||||||
import {
|
import {
|
||||||
LoginEmailServiceAbstraction,
|
LoginEmailServiceAbstraction,
|
||||||
LoginStrategyServiceAbstraction,
|
LoginStrategyServiceAbstraction,
|
||||||
|
LoginSuccessHandlerService,
|
||||||
PasswordLoginCredentials,
|
PasswordLoginCredentials,
|
||||||
RegisterRouteService,
|
RegisterRouteService,
|
||||||
} from "@bitwarden/auth/common";
|
} from "@bitwarden/auth/common";
|
||||||
|
@ -42,7 +43,6 @@ import {
|
||||||
LinkModule,
|
LinkModule,
|
||||||
ToastService,
|
ToastService,
|
||||||
} from "@bitwarden/components";
|
} from "@bitwarden/components";
|
||||||
import { UserAsymmetricKeysRegenerationService } from "@bitwarden/key-management";
|
|
||||||
|
|
||||||
import { AnonLayoutWrapperDataService } from "../anon-layout/anon-layout-wrapper-data.service";
|
import { AnonLayoutWrapperDataService } from "../anon-layout/anon-layout-wrapper-data.service";
|
||||||
import { VaultIcon, WaveIcon } from "../icons";
|
import { VaultIcon, WaveIcon } from "../icons";
|
||||||
|
@ -137,7 +137,7 @@ export class LoginComponent implements OnInit, OnDestroy {
|
||||||
private logService: LogService,
|
private logService: LogService,
|
||||||
private validationService: ValidationService,
|
private validationService: ValidationService,
|
||||||
private configService: ConfigService,
|
private configService: ConfigService,
|
||||||
private userAsymmetricKeysRegenerationService: UserAsymmetricKeysRegenerationService,
|
private loginSuccessHandlerService: LoginSuccessHandlerService,
|
||||||
) {
|
) {
|
||||||
this.clientType = this.platformUtilsService.getClientType();
|
this.clientType = this.platformUtilsService.getClientType();
|
||||||
}
|
}
|
||||||
|
@ -292,10 +292,7 @@ export class LoginComponent implements OnInit, OnDestroy {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.syncService.fullSync(true);
|
await this.loginSuccessHandlerService.run(authResult.userId);
|
||||||
await this.userAsymmetricKeysRegenerationService.handleUserAsymmetricKeysRegeneration(
|
|
||||||
authResult.userId,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (authResult.forcePasswordReset != ForceSetPasswordReason.None) {
|
if (authResult.forcePasswordReset != ForceSetPasswordReason.None) {
|
||||||
this.loginEmailService.clearValues();
|
this.loginEmailService.clearValues();
|
||||||
|
|
|
@ -4,3 +4,4 @@ export * from "./login-email.service";
|
||||||
export * from "./login-strategy.service";
|
export * from "./login-strategy.service";
|
||||||
export * from "./user-decryption-options.service.abstraction";
|
export * from "./user-decryption-options.service.abstraction";
|
||||||
export * from "./auth-request.service.abstraction";
|
export * from "./auth-request.service.abstraction";
|
||||||
|
export * from "./login-success-handler.service";
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
import { UserId } from "@bitwarden/common/types/guid";
|
||||||
|
|
||||||
|
export abstract class LoginSuccessHandlerService {
|
||||||
|
/**
|
||||||
|
* Runs any service calls required after a successful login.
|
||||||
|
* Service calls that should be included in this method are only those required to be awaited after successful login.
|
||||||
|
* @param userId The user id.
|
||||||
|
*/
|
||||||
|
abstract run: (userId: UserId) => Promise<void>;
|
||||||
|
}
|
|
@ -6,3 +6,4 @@ export * from "./auth-request/auth-request.service";
|
||||||
export * from "./auth-request/auth-request-api.service";
|
export * from "./auth-request/auth-request-api.service";
|
||||||
export * from "./register-route.service";
|
export * from "./register-route.service";
|
||||||
export * from "./accounts/lock.service";
|
export * from "./accounts/lock.service";
|
||||||
|
export * from "./login-success-handler/default-login-success-handler.service";
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
import { SyncService } from "@bitwarden/common/platform/sync";
|
||||||
|
import { UserId } from "@bitwarden/common/types/guid";
|
||||||
|
import { UserAsymmetricKeysRegenerationService } from "@bitwarden/key-management";
|
||||||
|
|
||||||
|
import { LoginSuccessHandlerService } from "../../abstractions/login-success-handler.service";
|
||||||
|
|
||||||
|
export class DefaultLoginSuccessHandlerService implements LoginSuccessHandlerService {
|
||||||
|
constructor(
|
||||||
|
private syncService: SyncService,
|
||||||
|
private userAsymmetricKeysRegenerationService: UserAsymmetricKeysRegenerationService,
|
||||||
|
) {}
|
||||||
|
async run(userId: UserId): Promise<void> {
|
||||||
|
await this.syncService.fullSync(true);
|
||||||
|
await this.userAsymmetricKeysRegenerationService.regenerateIfNeeded(userId);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue