fix: demo two fa

This commit is contained in:
Bereket Engida
2024-09-27 23:58:05 +03:00
parent adc1b8ebe4
commit 970cd3b945
2 changed files with 9 additions and 16 deletions

View File

@@ -22,20 +22,12 @@ export default function Component() {
const [message, setMessage] = useState("");
const [isError, setIsError] = useState(false);
const [isValidated, setIsValidated] = useState(false);
const [OTP, setOTP] = useState("");
// In a real app, this email would come from your authentication context
const userEmail = "user@example.com";
const requestOTP = async () => {
const res = await client.twoFactor.sendOtp({
fetchOptions: {
body: {
returnOTP: true,
},
},
});
setOTP(res.data?.OTP || "");
const res = await client.twoFactor.sendOtp();
// In a real app, this would call your backend API to send the OTP
setMessage("OTP sent to your email");
setIsError(false);
@@ -77,11 +69,7 @@ export default function Component() {
<div className="flex flex-col space-y-1.5">
<Label htmlFor="otp">One-Time Password</Label>
<Label className="py-2">
Use{" "}
<span className="text-blue-100 bg-slate-800 px-2">
{OTP}
</span>{" "}
(on real app, this would be sent to your email)
Check your email at {userEmail} for the OTP
</Label>
<Input
id="otp"

View File

@@ -70,8 +70,13 @@ export const auth = betterAuth({
}),
twoFactor({
otpOptions: {
sendOTP(user, otp) {
console.log({ otp });
async sendOTP(user, otp) {
await resend.emails.send({
from,
to: user.email,
subject: "Your OTP",
html: `Your OTP is ${otp}`,
});
},
},
}),