1
0
mirror of https://github.com/bitwarden/jslib synced 2025-12-12 14:23:20 +00:00

Use null coalescing to minimize let statements

This commit is contained in:
Thomas Rittson
2021-12-20 14:54:10 +10:00
parent 71b148c0f8
commit c8eedc5dd6

View File

@@ -65,7 +65,11 @@ export class AuthService implements AuthServiceAbstraction {
let key: SymmetricCryptoKey; let key: SymmetricCryptoKey;
let localHashedPassword: string; let localHashedPassword: string;
if (this.savedTokenRequest == null) { if (this.savedTokenRequest != null) {
tokenRequest = this.savedTokenRequest as PasswordTokenRequest;
key = this.key;
localHashedPassword = this.localHashedPassword;
} else {
key = await this.makePreloginKey(masterPassword, email); key = await this.makePreloginKey(masterPassword, email);
localHashedPassword = await this.cryptoService.hashPassword( localHashedPassword = await this.cryptoService.hashPassword(
masterPassword, masterPassword,
@@ -80,10 +84,6 @@ export class AuthService implements AuthServiceAbstraction {
await this.createTwoFactorData(twoFactor), await this.createTwoFactorData(twoFactor),
await this.createDeviceRequest() await this.createDeviceRequest()
); );
} else {
tokenRequest = this.savedTokenRequest as PasswordTokenRequest;
key = this.key;
localHashedPassword = this.localHashedPassword;
} }
const response = await this.apiService.postIdentityToken(tokenRequest); const response = await this.apiService.postIdentityToken(tokenRequest);
@@ -112,18 +112,13 @@ export class AuthService implements AuthServiceAbstraction {
): Promise<AuthResult> { ): Promise<AuthResult> {
this.twoFactorService.clearSelectedProvider(); this.twoFactorService.clearSelectedProvider();
let tokenRequest: SsoTokenRequest; const tokenRequest = this.savedTokenRequest ?? new SsoTokenRequest(
if (this.savedTokenRequest == null) { code,
tokenRequest = new SsoTokenRequest( codeVerifier,
code, redirectUrl,
codeVerifier, await this.createTwoFactorData(twoFactor),
redirectUrl, await this.createDeviceRequest()
await this.createTwoFactorData(twoFactor), );
await this.createDeviceRequest()
);
} else {
tokenRequest = this.savedTokenRequest as SsoTokenRequest;
}
const response = await this.apiService.postIdentityToken(tokenRequest); const response = await this.apiService.postIdentityToken(tokenRequest);
const tokenResponse = response as IdentityTokenResponse; const tokenResponse = response as IdentityTokenResponse;
@@ -160,17 +155,12 @@ export class AuthService implements AuthServiceAbstraction {
): Promise<AuthResult> { ): Promise<AuthResult> {
this.twoFactorService.clearSelectedProvider(); this.twoFactorService.clearSelectedProvider();
let tokenRequest: ApiTokenRequest; const tokenRequest = this.savedTokenRequest ?? new ApiTokenRequest(
if (this.savedTokenRequest == null) { clientId,
tokenRequest = new ApiTokenRequest( clientSecret,
clientId, await this.createTwoFactorData(twoFactor),
clientSecret, await this.createDeviceRequest()
await this.createTwoFactorData(twoFactor), );
await this.createDeviceRequest()
);
} else {
tokenRequest = this.savedTokenRequest as ApiTokenRequest;
}
const response = await this.apiService.postIdentityToken(tokenRequest); const response = await this.apiService.postIdentityToken(tokenRequest);
@@ -189,7 +179,6 @@ export class AuthService implements AuthServiceAbstraction {
if (result.requiresTwoFactor) { if (result.requiresTwoFactor) {
this.saveState(tokenRequest, result.twoFactorProviders); this.saveState(tokenRequest, result.twoFactorProviders);
return result;
} }
return result; return result;