mirror of
https://github.com/LukeHagar/better-auth.git
synced 2025-12-09 12:27:43 +00:00
fix: demo two fa
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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}`,
|
||||
});
|
||||
},
|
||||
},
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user