1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-09 21:20:27 +00:00

Add "component" to file name and variables for clarity

This commit is contained in:
Alec Rippberger
2025-04-15 16:33:10 -05:00
parent d09293a934
commit 6ee84f502c
3 changed files with 35 additions and 31 deletions

View File

@@ -48,8 +48,8 @@ import {
import {
TwoFactorAuthComponentCacheService,
TwoFactorAuthData,
} from "../../common/services/auth-request/two-factor-auth-cache.service";
TwoFactorAuthComponentData,
} from "../../common/services/auth-request/two-factor-auth-component-cache.service";
import { AnonLayoutWrapperDataService } from "../anon-layout/anon-layout-wrapper-data.service";
import {
TwoFactorAuthAuthenticatorIcon,
@@ -110,7 +110,7 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy {
orgSsoIdentifier: string | undefined = undefined;
providerType = TwoFactorProviderType;
selectedProviderType: TwoFactorProviderType | undefined = undefined;
selectedProviderType: TwoFactorProviderType = TwoFactorProviderType.Authenticator;
// TODO: PM-17176 - build more specific type for 2FA metadata
twoFactorProviders: Map<TwoFactorProviderType, { [key: string]: string }> | null = null;
@@ -168,7 +168,7 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy {
private anonLayoutWrapperDataService: AnonLayoutWrapperDataService,
private environmentService: EnvironmentService,
private loginSuccessHandlerService: LoginSuccessHandlerService,
private twoFactorCacheService: TwoFactorAuthComponentCacheService,
private twoFactorAuthComponentCacheService: TwoFactorAuthComponentCacheService,
) {}
async ngOnInit() {
@@ -178,11 +178,11 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy {
this.listenForAuthnSessionTimeout();
// Initialize the cache
await this.twoFactorCacheService.init();
await this.twoFactorAuthComponentCacheService.init();
// Load persisted form data if available
let loadedCachedProviderType = false;
const persistedData = this.twoFactorCacheService.getCachedData();
const persistedData = this.twoFactorAuthComponentCacheService.getCachedData();
if (persistedData) {
if (persistedData.token) {
this.form.patchValue({ token: persistedData.token });
@@ -216,11 +216,11 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy {
/**
* Save specific form data fields to the cache
*/
async saveFormDataWithPartialData(data: Partial<TwoFactorAuthData>) {
async saveFormDataWithPartialData(data: Partial<TwoFactorAuthComponentData>) {
// Get current cached data
const currentData = this.twoFactorCacheService.getCachedData();
const currentData = this.twoFactorAuthComponentCacheService.getCachedData();
this.twoFactorCacheService.cacheData({
this.twoFactorAuthComponentCacheService.cacheData({
token: data?.token ?? currentData?.token ?? "",
remember: data?.remember ?? currentData?.remember ?? false,
selectedProviderType: data?.selectedProviderType ?? currentData?.selectedProviderType,
@@ -231,7 +231,7 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy {
* Save all current form data to the cache
*/
async saveFormData() {
const formData: TwoFactorAuthData = {
const formData: TwoFactorAuthComponentData = {
token: this.tokenFormControl.value || undefined,
remember: this.rememberFormControl.value ?? undefined,
selectedProviderType: this.selectedProviderType,
@@ -259,8 +259,10 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy {
private async set2faProvidersAndData() {
this.twoFactorProviders = await this.twoFactorService.getProviders();
const providerData = this.twoFactorProviders?.get(this.selectedProviderType);
this.selectedProviderData = providerData;
if (this.selectedProviderType !== undefined) {
const providerData = this.twoFactorProviders?.get(this.selectedProviderType);
this.selectedProviderData = providerData;
}
}
private listenForAuthnSessionTimeout() {
@@ -327,7 +329,7 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy {
const rememberValue = remember ?? this.rememberFormControl.value ?? false;
// Persist form data before submitting
this.twoFactorCacheService.cacheData({
this.twoFactorAuthComponentCacheService.cacheData({
token: tokenValue,
remember: rememberValue,
selectedProviderType: this.selectedProviderType,
@@ -354,7 +356,7 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy {
async selectOtherTwoFactorMethod() {
// Persist current form data before navigating to another method
this.twoFactorCacheService.cacheData({
this.twoFactorAuthComponentCacheService.cacheData({
token: "",
remember: false,
selectedProviderType: this.selectedProviderType,
@@ -374,7 +376,7 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy {
await this.setAnonLayoutDataByTwoFactorProviderType();
// Update the persisted provider type when a new one is chosen
this.twoFactorCacheService.cacheData({
this.twoFactorAuthComponentCacheService.cacheData({
token: "",
remember: false,
selectedProviderType: response.type,
@@ -458,7 +460,7 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy {
private async handleAuthResult(authResult: AuthResult) {
// Clear form cache
this.twoFactorCacheService.clearCachedData();
this.twoFactorAuthComponentCacheService.clearCachedData();
if (await this.handleMigrateEncryptionKey(authResult)) {
return; // stop login process

View File

@@ -6,27 +6,29 @@ import { TwoFactorProviderType } from "@bitwarden/common/auth/enums/two-factor-p
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
const TWO_FACTOR_AUTH_CACHE_KEY = "two-factor-auth-cache";
const TWO_FACTOR_AUTH_COMPONENT_CACHE_KEY = "two-factor-auth-component-cache";
/**
* This is a cache model for the two factor authentication data.
*/
export class TwoFactorAuthCache {
export class TwoFactorAuthComponentCache {
token: string | undefined = undefined;
remember: boolean | undefined = undefined;
selectedProviderType: TwoFactorProviderType | undefined = undefined;
static fromJSON(obj: Partial<Jsonify<TwoFactorAuthCache>>): TwoFactorAuthCache | null {
static fromJSON(
obj: Partial<Jsonify<TwoFactorAuthComponentCache>>,
): TwoFactorAuthComponentCache | null {
// Return null if the cache is empty
if (obj == null) {
return null;
}
return Object.assign(new TwoFactorAuthCache(), obj);
return Object.assign(new TwoFactorAuthComponentCache(), obj);
}
}
export interface TwoFactorAuthData {
export interface TwoFactorAuthComponentData {
token?: string;
remember?: boolean;
selectedProviderType?: TwoFactorProviderType;
@@ -49,11 +51,11 @@ export class TwoFactorAuthComponentCacheService {
/**
* Signal for the cached TwoFactorAuthData.
*/
private twoFactorAuthCache: WritableSignal<TwoFactorAuthCache | null> =
this.viewCacheService.signal<TwoFactorAuthCache | null>({
key: TWO_FACTOR_AUTH_CACHE_KEY,
private twoFactorAuthComponentCache: WritableSignal<TwoFactorAuthComponentCache | null> =
this.viewCacheService.signal<TwoFactorAuthComponentCache | null>({
key: TWO_FACTOR_AUTH_COMPONENT_CACHE_KEY,
initialValue: null,
deserializer: TwoFactorAuthCache.fromJSON,
deserializer: TwoFactorAuthComponentCache.fromJSON,
});
constructor() {}
@@ -70,16 +72,16 @@ export class TwoFactorAuthComponentCacheService {
/**
* Update the cache with the new TwoFactorAuthData.
*/
cacheData(data: TwoFactorAuthData): void {
cacheData(data: TwoFactorAuthComponentData): void {
if (!this.featureEnabled) {
return;
}
this.twoFactorAuthCache.set({
this.twoFactorAuthComponentCache.set({
token: data.token,
remember: data.remember,
selectedProviderType: data.selectedProviderType,
} as TwoFactorAuthCache);
} as TwoFactorAuthComponentCache);
}
/**
@@ -90,17 +92,17 @@ export class TwoFactorAuthComponentCacheService {
return;
}
this.twoFactorAuthCache.set(null);
this.twoFactorAuthComponentCache.set(null);
}
/**
* Returns the cached TwoFactorAuthData when available.
*/
getCachedData(): TwoFactorAuthCache | null {
getCachedData(): TwoFactorAuthComponentCache | null {
if (!this.featureEnabled) {
return null;
}
return this.twoFactorAuthCache();
return this.twoFactorAuthComponentCache();
}
}