Skip to content

Commit 5795471

Browse files
committed
fix(angular): Use recaptcha verifier behavior
1 parent d678f79 commit 5795471

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

packages/angular/src/lib/auth/forms/mfa/sms-multi-factor-assertion-form.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { injectForm, injectStore, TanStackAppField, TanStackField } from "@tanst
1919
import {
2020
injectMultiFactorPhoneAuthNumberFormSchema,
2121
injectMultiFactorPhoneAuthVerifyFormSchema,
22+
injectRecaptchaVerifier,
2223
injectTranslation,
2324
injectUI,
2425
} from "../../../provider";
@@ -87,11 +88,7 @@ export class SmsMultiFactorAssertionPhoneFormComponent {
8788
return hint.phoneNumber || "";
8889
});
8990

90-
recaptchaVerifier = computed(() => {
91-
return new RecaptchaVerifier(this.ui().auth, this.recaptchaContainer().nativeElement, {
92-
size: "normal",
93-
});
94-
});
91+
recaptchaVerifier = injectRecaptchaVerifier(this.recaptchaContainer());
9592

9693
form = injectForm({
9794
defaultValues: {

packages/angular/src/lib/auth/forms/mfa/sms-multi-factor-enrollment-form.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
injectMultiFactorPhoneAuthNumberFormSchema,
3737
injectMultiFactorPhoneAuthVerifyFormSchema,
3838
injectDefaultCountry,
39+
injectRecaptchaVerifier,
3940
} from "../../../provider";
4041

4142
@Component({
@@ -126,11 +127,7 @@ export class SmsMultiFactorEnrollmentFormComponent {
126127

127128
recaptchaContainer = viewChild.required<ElementRef<HTMLDivElement>>("recaptchaContainer");
128129

129-
recaptchaVerifier = computed(() => {
130-
return new RecaptchaVerifier(this.ui().auth, this.recaptchaContainer().nativeElement, {
131-
size: "normal",
132-
});
133-
});
130+
recaptchaVerifier = injectRecaptchaVerifier(this.recaptchaContainer());
134131

135132
phoneForm = injectForm({
136133
defaultValues: {

packages/angular/src/lib/auth/forms/phone-auth-form.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { injectForm, injectStore, TanStackAppField, TanStackField } from "@tanst
2020
import {
2121
injectPhoneAuthFormSchema,
2222
injectPhoneAuthVerifyFormSchema,
23+
injectRecaptchaVerifier,
2324
injectTranslation,
2425
injectUI,
2526
} from "../../provider";
@@ -85,12 +86,7 @@ export class PhoneNumberFormComponent {
8586
unknownErrorLabel = injectTranslation("errors", "unknownError");
8687

8788
recaptchaContainer = viewChild.required<ElementRef<HTMLDivElement>>("recaptchaContainer");
88-
89-
recaptchaVerifier = computed(() => {
90-
return new RecaptchaVerifier(this.ui().auth, this.recaptchaContainer().nativeElement, {
91-
size: "normal", // TODO(ehesp): Get this from the ui behavior
92-
});
93-
});
89+
recaptchaVerifier = injectRecaptchaVerifier(this.recaptchaContainer());
9490

9591
form = injectForm({
9692
defaultValues: {

packages/angular/src/lib/provider.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
computed,
2525
effect,
2626
Signal,
27+
ElementRef,
2728
} from "@angular/core";
2829
import { FirebaseApps } from "@angular/fire/app";
2930
import {
@@ -77,7 +78,6 @@ export function provideFirebaseUIPolicies(factory: () => PolicyConfig) {
7778
return makeEnvironmentProviders(providers);
7879
}
7980

80-
// Provides a signal with a subscription to the FirebaseUIStore
8181
export function injectUI() {
8282
const store = inject(FIREBASE_UI_STORE);
8383
const ui = signal<FirebaseUIType>(store.get());
@@ -89,6 +89,20 @@ export function injectUI() {
8989
return ui.asReadonly();
9090
}
9191

92+
export function injectRecaptchaVerifier(element: ElementRef<HTMLDivElement>) {
93+
const ui = injectUI();
94+
const verifier = computed(() => getBehavior(ui(), "recaptchaVerification")(ui(), element.nativeElement));
95+
96+
effect(() => {
97+
if (verifier()) {
98+
verifier().render();
99+
}
100+
});
101+
102+
return verifier;
103+
104+
}
105+
92106
export function injectTranslation(category: string, key: string) {
93107
const ui = injectUI();
94108
return computed(() => getTranslation(ui(), category as any, key as any));

0 commit comments

Comments
 (0)