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 [message, setMessage] = useState("");
|
||||||
const [isError, setIsError] = useState(false);
|
const [isError, setIsError] = useState(false);
|
||||||
const [isValidated, setIsValidated] = useState(false);
|
const [isValidated, setIsValidated] = useState(false);
|
||||||
const [OTP, setOTP] = useState("");
|
|
||||||
|
|
||||||
// In a real app, this email would come from your authentication context
|
// In a real app, this email would come from your authentication context
|
||||||
const userEmail = "user@example.com";
|
const userEmail = "user@example.com";
|
||||||
|
|
||||||
const requestOTP = async () => {
|
const requestOTP = async () => {
|
||||||
const res = await client.twoFactor.sendOtp({
|
const res = await client.twoFactor.sendOtp();
|
||||||
fetchOptions: {
|
|
||||||
body: {
|
|
||||||
returnOTP: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
setOTP(res.data?.OTP || "");
|
|
||||||
// In a real app, this would call your backend API to send the OTP
|
// In a real app, this would call your backend API to send the OTP
|
||||||
setMessage("OTP sent to your email");
|
setMessage("OTP sent to your email");
|
||||||
setIsError(false);
|
setIsError(false);
|
||||||
@@ -77,11 +69,7 @@ export default function Component() {
|
|||||||
<div className="flex flex-col space-y-1.5">
|
<div className="flex flex-col space-y-1.5">
|
||||||
<Label htmlFor="otp">One-Time Password</Label>
|
<Label htmlFor="otp">One-Time Password</Label>
|
||||||
<Label className="py-2">
|
<Label className="py-2">
|
||||||
Use{" "}
|
Check your email at {userEmail} for the OTP
|
||||||
<span className="text-blue-100 bg-slate-800 px-2">
|
|
||||||
{OTP}
|
|
||||||
</span>{" "}
|
|
||||||
(on real app, this would be sent to your email)
|
|
||||||
</Label>
|
</Label>
|
||||||
<Input
|
<Input
|
||||||
id="otp"
|
id="otp"
|
||||||
|
|||||||
@@ -70,8 +70,13 @@ export const auth = betterAuth({
|
|||||||
}),
|
}),
|
||||||
twoFactor({
|
twoFactor({
|
||||||
otpOptions: {
|
otpOptions: {
|
||||||
sendOTP(user, otp) {
|
async sendOTP(user, otp) {
|
||||||
console.log({ otp });
|
await resend.emails.send({
|
||||||
|
from,
|
||||||
|
to: user.email,
|
||||||
|
subject: "Your OTP",
|
||||||
|
html: `Your OTP is ${otp}`,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in New Issue
Block a user