Error on Signup with OTP

//auth.ts
import { betterAuth, BetterAuthOptions } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
import { admin, emailOTP, openAPI, twoFactor } from "better-auth/plugins";
import { sendEmail } from "./actions/email";
import prisma from "./lib/prisma";

export const auth = betterAuth({
database: prismaAdapter(prisma, {
provider: "postgresql",
}),
plugins: [
admin(),
twoFactor(),
openAPI(),
emailOTP({
sendVerificationOnSignUp: true,
disableSignUp: true,
async sendVerificationOTP({ email, otp, type }) {
await sendEmail({ to: email, type, otp });
},
}),
],
session: {
expiresIn: 60 * 60 * 24 * 7, // 7 days
updateAge: 60 * 60 * 24, // 1 day (every 1 day the session expiration is updated)
cookieCache: {
enabled: true,
maxAge: 5 * 60, // 300 seconds (5 minutes)
},
},
account: {
accountLinking: {
enabled: true,
},
},
emailAndPassword: {
enabled: true,
autoSignIn: false,
},
emailVerification: {
autoSignInAfterVerification: true,

},
socialProviders: {
google: {
clientId: process.env.GOOGLE_CLIENT_ID as string,
clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
},
github: {
clientId: process.env.GITHUB_CLIENT_ID as string,
clientSecret: process.env.GITHUB_CLIENT_SECRET as string,
},
},
} satisfies BetterAuthOptions);

export type Session = typeof auth.$Infer.Session;
import { betterAuth, BetterAuthOptions } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
import { admin, emailOTP, openAPI, twoFactor } from "better-auth/plugins";
import { sendEmail } from "./actions/email";
import prisma from "./lib/prisma";

export const auth = betterAuth({
database: prismaAdapter(prisma, {
provider: "postgresql",
}),
plugins: [
admin(),
twoFactor(),
openAPI(),
emailOTP({
sendVerificationOnSignUp: true,
disableSignUp: true,
async sendVerificationOTP({ email, otp, type }) {
await sendEmail({ to: email, type, otp });
},
}),
],
session: {
expiresIn: 60 * 60 * 24 * 7, // 7 days
updateAge: 60 * 60 * 24, // 1 day (every 1 day the session expiration is updated)
cookieCache: {
enabled: true,
maxAge: 5 * 60, // 300 seconds (5 minutes)
},
},
account: {
accountLinking: {
enabled: true,
},
},
emailAndPassword: {
enabled: true,
autoSignIn: false,
},
emailVerification: {
autoSignInAfterVerification: true,

},
socialProviders: {
google: {
clientId: process.env.GOOGLE_CLIENT_ID as string,
clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
},
github: {
clientId: process.env.GITHUB_CLIENT_ID as string,
clientSecret: process.env.GITHUB_CLIENT_SECRET as string,
},
},
} satisfies BetterAuthOptions);

export type Session = typeof auth.$Infer.Session;
After signup a otp is sent to user's email then i i try to verifiy otp and signin like that:
await signIn.emailOtp(
{
email: userData.email,
otp: data.otp,
},
await signIn.emailOtp(
{
email: userData.email,
otp: data.otp,
},
I got error even the otp is coorect. error: Invalid otp. Please help me how to fix this
4 Replies
Shyam Verma
Shyam VermaOP2w ago
Hey! Is there is somone please help me
Ping
Ping2w ago
Are you 100% sure that your data.otp value is correct?
Shyam Verma
Shyam VermaOP2w ago
yes i am sure I had match both otp store in database and otp which was sent
Ping
Ping7d ago
@Shyam Verma Can you show me your verification table in your DB? I would like to check something.

Did you find this page helpful?