11"use client" ;
22
3- import {
4- PhoneMultiFactorGenerator ,
5- TotpMultiFactorGenerator ,
6- type UserCredential ,
7- type MultiFactorInfo ,
8- } from "firebase/auth" ;
3+ import { PhoneMultiFactorGenerator , TotpMultiFactorGenerator , type MultiFactorInfo } from "firebase/auth" ;
94import { type ComponentProps , useState } from "react" ;
105import { getTranslation } from "@invertase/firebaseui-core" ;
116import { useUI } from "@invertase/firebaseui-react" ;
7+ import { useEffect } from "react" ;
128
13- import { SmsMultiFactorAssertionForm } from ". /sms-multi-factor-assertion-form" ;
14- import { TotpMultiFactorAssertionForm } from ". /totp-multi-factor-assertion-form" ;
9+ import { SmsMultiFactorAssertionForm } from "@/components /sms-multi-factor-assertion-form" ;
10+ import { TotpMultiFactorAssertionForm } from "@/components /totp-multi-factor-assertion-form" ;
1511import { Button } from "@/components/ui/button" ;
1612
17- export type MultiFactorAuthAssertionFormProps = {
18- onSuccess ?: ( credential : UserCredential ) => void ;
19- } ;
20-
21- export function MultiFactorAuthAssertionForm ( { onSuccess } : MultiFactorAuthAssertionFormProps ) {
13+ export function MultiFactorAuthAssertionForm ( ) {
2214 const ui = useUI ( ) ;
2315 const resolver = ui . multiFactorResolver ;
2416
17+ useEffect ( ( ) => {
18+ return ( ) => {
19+ ui . setMultiFactorResolver ( ) ;
20+ } ;
21+ } , [ ] ) ;
22+
2523 if ( ! resolver ) {
2624 throw new Error ( "MultiFactorAuthAssertionForm requires a multi-factor resolver" ) ;
2725 }
@@ -33,17 +31,17 @@ export function MultiFactorAuthAssertionForm({ onSuccess }: MultiFactorAuthAsser
3331
3432 if ( hint ) {
3533 if ( hint . factorId === PhoneMultiFactorGenerator . FACTOR_ID ) {
36- return < SmsMultiFactorAssertionForm hint = { hint } onSuccess = { ( credential ) => onSuccess ?. ( credential ) } /> ;
34+ return < SmsMultiFactorAssertionForm hint = { hint } /> ;
3735 }
3836
3937 if ( hint . factorId === TotpMultiFactorGenerator . FACTOR_ID ) {
40- return < TotpMultiFactorAssertionForm hint = { hint } onSuccess = { ( credential ) => onSuccess ?. ( credential ) } /> ;
38+ return < TotpMultiFactorAssertionForm hint = { hint } /> ;
4139 }
4240 }
4341
4442 return (
45- < div className = "flex flex-col gap -2" >
46- < p className = "text-sm text-muted-foreground" > TODO: Select a multi-factor authentication method</ p >
43+ < div className = "space-y -2" >
44+ < p className = "text-sm text-muted-foreground" > Select a multi-factor authentication method</ p >
4745 { resolver . hints . map ( ( hint ) => {
4846 if ( hint . factorId === TotpMultiFactorGenerator . FACTOR_ID ) {
4947 return < TotpButton key = { hint . factorId } onClick = { ( ) => setHint ( hint ) } /> ;
@@ -62,19 +60,11 @@ export function MultiFactorAuthAssertionForm({ onSuccess }: MultiFactorAuthAsser
6260function TotpButton ( props : ComponentProps < typeof Button > ) {
6361 const ui = useUI ( ) ;
6462 const labelText = getTranslation ( ui , "labels" , "mfaTotpVerification" ) ;
65- return (
66- < Button { ...props } variant = "outline" >
67- { labelText }
68- </ Button >
69- ) ;
63+ return < Button { ...props } > { labelText } </ Button > ;
7064}
7165
7266function SmsButton ( props : ComponentProps < typeof Button > ) {
7367 const ui = useUI ( ) ;
7468 const labelText = getTranslation ( ui , "labels" , "mfaSmsVerification" ) ;
75- return (
76- < Button { ...props } variant = "outline" >
77- { labelText }
78- </ Button >
79- ) ;
69+ return < Button { ...props } > { labelText } </ Button > ;
8070}
0 commit comments