BA
Better Auth•2mo ago
Wizzel

Is there a way to create an "always valid" OTP for testing?

I am currently migrating from clerk to better-auth and I am wondering if there is a way to create OTPs that are always valid
Solution:
GitHub
chore(email-otp): Allow returning undefined in generateOTP by pin...
Right now you're forced to return an OTP value in the generateOTP function as part of the email-otp plugin. In some cases you may just want to return an OTP under a specific case, and just ...
Jump to solution
10 Replies
Ping
Ping•2mo ago
2fa otps? or email-otps?
Wizzel
WizzelOP•2mo ago
Email otp
Ping
Ping•2mo ago
Do you mean an OTP that once verified remains valid? or an otp that doesn't expire?
Wizzel
WizzelOP•2mo ago
With clerk I could use 424242 as otp for any test email on the dev environment I am wondering if I can replicate this with better auth
Ping
Ping•2mo ago
you can probably do this by passing generateOTP fn into the emaiil otp plugin options and just return 424242 if on dev
Wizzel
WizzelOP•2mo ago
Ah interesting, I will try that @Ping worked perfectly thanks again. However I had to search a bit until I found your createRandomStringGenerator utility function because I wanted to stay as close to your implementation as possible. Maybe its a good idea to generate a OTP in all cases and allow the user to intercept it. Something along thos lines:
generateOTP(data, otp, _) {
if (TEST_EMAILS.includes(data.email)) return "424242";
return otp;
},
generateOTP(data, otp, _) {
if (TEST_EMAILS.includes(data.email)) return "424242";
return otp;
},
I am not sure about the implications, just my two cents.
Ping
Ping•2mo ago
Thanks for the feedback!
Wizzel
WizzelOP•2mo ago
Thanks for the amazing project, recommending it everywhere!
Solution
Ping
Ping•2mo ago
GitHub
chore(email-otp): Allow returning undefined in generateOTP by pin...
Right now you're forced to return an OTP value in the generateOTP function as part of the email-otp plugin. In some cases you may just want to return an OTP under a specific case, and just ...
Wizzel
WizzelOP•2mo ago
Wow that was fast 🤩

Did you find this page helpful?