//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:
I got error even the otp is coorect. error: Invalid otp.
Please help me how to fix this