Skip to content

Commit 96cdd92

Browse files
committed
fix(shadcn): updated mfa assertion form re-render
1 parent 59c6942 commit 96cdd92

File tree

4 files changed

+38
-58
lines changed

4 files changed

+38
-58
lines changed
Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
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";
94
import { type ComponentProps, useState } from "react";
105
import { getTranslation } from "@invertase/firebaseui-core";
116
import { 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";
1511
import { 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
6260
function 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

7266
function 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
}

packages/shadcn/registry-spec.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@
249249
"type": "registry:block",
250250
"title": "Multi-Factor Auth Assertion Screen",
251251
"description": "A screen allowing users to complete multi-factor authentication during sign-in with TOTP or SMS options.",
252-
"dependencies": ["{{ DEP | @firebase-ui/react }}"],
252+
"dependencies": ["{{ DEP | @invertase/firebaseui-react }}"],
253253
"registryDependencies": ["card", "{{ DOMAIN }}/r/multi-factor-auth-assertion-form.json"],
254254
"files": [
255255
{
Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
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";
94
import { type ComponentProps, useState } from "react";
105
import { getTranslation } from "@invertase/firebaseui-core";
116
import { 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";
1511
import { 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
6260
function 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

7266
function 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
}

pnpm-lock.yaml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)