diff --git a/common/src/models/domain/authResult.ts b/common/src/models/domain/authResult.ts index eadad50f..50b70f72 100644 --- a/common/src/models/domain/authResult.ts +++ b/common/src/models/domain/authResult.ts @@ -1,9 +1,19 @@ import { TwoFactorProviderType } from "../../enums/twoFactorProviderType"; +import { Utils } from "../../misc/utils"; + export class AuthResult { twoFactor: boolean = false; captchaSiteKey: string = ""; resetMasterPassword: boolean = false; forcePasswordReset: boolean = false; twoFactorProviders: Map = null; + + get requiresCaptcha() { + return !Utils.isNullOrWhitespace(this.captchaSiteKey); + } + + get requiresTwoFactor() { + return this.twoFactor; + } } diff --git a/common/src/services/auth.service.ts b/common/src/services/auth.service.ts index a639052b..cfa55101 100644 --- a/common/src/services/auth.service.ts +++ b/common/src/services/auth.service.ts @@ -270,12 +270,12 @@ export class AuthService implements AuthServiceAbstraction { const result = new AuthResult(); result.captchaSiteKey = (response as any).siteKey; - if (!!result.captchaSiteKey) { + if (result.requiresCaptcha) { return result; } - result.twoFactor = !!(response as any).twoFactorProviders2; - if (result.twoFactor) { + result.twoFactor = (response as any).twoFactorProviders2 != null; + if (result.requiresTwoFactor) { result.twoFactorProviders = (response as IdentityTwoFactorResponse).twoFactorProviders2; return result; } diff --git a/spec/common/services/auth.service.spec.ts b/spec/common/services/auth.service.spec.ts index effee700..a0c205ee 100644 --- a/spec/common/services/auth.service.spec.ts +++ b/spec/common/services/auth.service.spec.ts @@ -155,7 +155,7 @@ describe("Cipher Service", () => { function newTokenResponse() { const tokenResponse = new IdentityTokenResponse({}); - (tokenResponse as any).twoFactorProviders2 = false; + (tokenResponse as any).twoFactorProviders2 = null; (tokenResponse as any).siteKey = undefined; tokenResponse.resetMasterPassword = false; tokenResponse.forcePasswordReset = false;