Skip to content

Commit e5d8ab5

Browse files
authored
Merge f2da945 into e2847db
2 parents e2847db + f2da945 commit e5d8ab5

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

packages/auth/src/platform_browser/providers/phone.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe('platform_browser/providers/phone', () => {
6464
context('#verifyPhoneNumber', () => {
6565
it('calls verify on the appVerifier and then calls the server when recaptcha enterprise is disabled', async () => {
6666
const recaptchaConfigResponseOff = {
67-
recaptchaKey: 'foo/bar/to/site-key',
67+
// no recaptcha key if no rCE provider is enabled
6868
recaptchaEnforcementState: [
6969
{
7070
provider: RecaptchaAuthProvider.PHONE_PROVIDER,
@@ -111,7 +111,7 @@ describe('platform_browser/providers/phone', () => {
111111

112112
it('throws an error if verify without appVerifier when recaptcha enterprise is disabled', async () => {
113113
const recaptchaConfigResponseOff = {
114-
recaptchaKey: 'foo/bar/to/site-key',
114+
// no recaptcha key if no rCE provider is enabled
115115
recaptchaEnforcementState: [
116116
{
117117
provider: RecaptchaAuthProvider.PHONE_PROVIDER,

packages/auth/src/platform_browser/strategies/phone.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const recaptchaConfigResponseAudit = {
8383
]
8484
};
8585
const recaptchaConfigResponseOff = {
86-
recaptchaKey: 'foo/bar/to/site-key',
86+
// no recaptcha key if no rCE provider is enabled
8787
recaptchaEnforcementState: [
8888
{
8989
provider: RecaptchaAuthProvider.PHONE_PROVIDER,

packages/auth/src/platform_browser/strategies/phone.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ import { _castAuth } from '../../core/auth/auth_impl';
6868
import { getModularInstance } from '@firebase/util';
6969
import { ProviderId } from '../../model/enums';
7070
import {
71-
RecaptchaEnterpriseVerifier,
7271
FAKE_TOKEN,
73-
handleRecaptchaFlow
72+
handleRecaptchaFlow,
73+
_initializeRecaptchaConfig
7474
} from '../recaptcha/recaptcha_enterprise_verifier';
7575
import { _isFirebaseServerApp } from '@firebase/app';
7676

@@ -227,8 +227,17 @@ export async function _verifyPhoneNumber(
227227
verifier?: ApplicationVerifierInternal
228228
): Promise<string> {
229229
if (!auth._getRecaptchaConfig()) {
230-
const enterpriseVerifier = new RecaptchaEnterpriseVerifier(auth);
231-
await enterpriseVerifier.verify();
230+
try {
231+
await _initializeRecaptchaConfig(auth);
232+
} catch (error) {
233+
// If an error occurs while fetching the config, there is no way to know the enablement state
234+
// of Phone provider, so we proceed with recaptcha V2 verification.
235+
// The error is likely "recaptchaKey undefined", as reCAPTCHA Enterprise is not
236+
// enabled for any provider.
237+
console.log(
238+
'Failed to initialize reCAPTCHA Enterprise config. Triggering the reCAPTCHA v2 verification.'
239+
);
240+
}
232241
}
233242

234243
try {

0 commit comments

Comments
 (0)