Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/auth/src/platform_browser/providers/phone.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('platform_browser/providers/phone', () => {
context('#verifyPhoneNumber', () => {
it('calls verify on the appVerifier and then calls the server when recaptcha enterprise is disabled', async () => {
const recaptchaConfigResponseOff = {
recaptchaKey: 'foo/bar/to/site-key',
// no recaptcha key if no rCE provider is enabled
recaptchaEnforcementState: [
{
provider: RecaptchaAuthProvider.PHONE_PROVIDER,
Expand Down Expand Up @@ -111,7 +111,7 @@ describe('platform_browser/providers/phone', () => {

it('throws an error if verify without appVerifier when recaptcha enterprise is disabled', async () => {
const recaptchaConfigResponseOff = {
recaptchaKey: 'foo/bar/to/site-key',
// no recaptcha key if no rCE provider is enabled
recaptchaEnforcementState: [
{
provider: RecaptchaAuthProvider.PHONE_PROVIDER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const recaptchaConfigResponseAudit = {
]
};
const recaptchaConfigResponseOff = {
recaptchaKey: 'foo/bar/to/site-key',
// no recaptcha key if no rCE provider is enabled
recaptchaEnforcementState: [
{
provider: RecaptchaAuthProvider.PHONE_PROVIDER,
Expand Down
17 changes: 13 additions & 4 deletions packages/auth/src/platform_browser/strategies/phone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ import { _castAuth } from '../../core/auth/auth_impl';
import { getModularInstance } from '@firebase/util';
import { ProviderId } from '../../model/enums';
import {
RecaptchaEnterpriseVerifier,
FAKE_TOKEN,
handleRecaptchaFlow
handleRecaptchaFlow,
_initializeRecaptchaConfig
} from '../recaptcha/recaptcha_enterprise_verifier';
import { _isFirebaseServerApp } from '@firebase/app';

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

try {
Expand Down
Loading