Patrick
BABetter Auth
•Created by Patrick on 3/31/2025 in #help
Unable to send OTP
When executing sendVerificationOTP i get an error, all versions are up to date (drizzle-kit, drizzle-orm, better-auth)
Error:
auth.ts
const response = await auth.api.sendVerificationOTP({
body: { email, type: 'sign-in' },
asResponse: true
});
const response = await auth.api.sendVerificationOTP({
body: { email, type: 'sign-in' },
asResponse: true
});
message = 'db.delete is not a function'
stack = 'TypeError: db.delete is not a function
at Object.delete (..sveltekit/node_modules/better-auth/dist/adapters/drizzle-adapter/index.mjs:274:32)
at Object.deleteVerificationByIdentifier (..sveltekit/node_modules/better-auth/dist/shared/better-auth.CbBX7Xla.mjs:794:27)
at ..sveltekit/node_module…/api/index.mjs:480:22)
at async requestOTP (../src/routes/(auth)/login/+page.server.ts:20:24)
at async handle_action_json_request (../node_modules/@sveltejs/kit/src/runtime/server/page/actions.js:44:18)
at async resolve (../node_modules/@sveltejs/kit/src/runtime/server/respond.js:381:24)'
message = 'db.delete is not a function'
stack = 'TypeError: db.delete is not a function
at Object.delete (..sveltekit/node_modules/better-auth/dist/adapters/drizzle-adapter/index.mjs:274:32)
at Object.deleteVerificationByIdentifier (..sveltekit/node_modules/better-auth/dist/shared/better-auth.CbBX7Xla.mjs:794:27)
at ..sveltekit/node_module…/api/index.mjs:480:22)
at async requestOTP (../src/routes/(auth)/login/+page.server.ts:20:24)
at async handle_action_json_request (../node_modules/@sveltejs/kit/src/runtime/server/page/actions.js:44:18)
at async resolve (../node_modules/@sveltejs/kit/src/runtime/server/respond.js:381:24)'
import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { admin, emailOTP, organization } from "better-auth/plugins"
import { sendOTPEmail } from "./email";
import { isFailure } from "./types";
import { getNativeClient } from "./connection";
import * as schema from "../db/schema";
// Get the database client
const dbClient = await getNativeClient();
if (!dbClient) throw new Error("Database client initialization failed");
export const auth = betterAuth({
database: drizzleAdapter(dbClient, {
provider: "pg",
schema
}),
plugins: [
admin(),
organization(),
emailOTP({
async sendVerificationOTP({ email, otp, type }) {
if (type === "sign-in") {
const result = await sendOTPEmail(email, otp)
if (isFailure(result)) {
console.error(result.error)
}
}
}
})]
});
import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { admin, emailOTP, organization } from "better-auth/plugins"
import { sendOTPEmail } from "./email";
import { isFailure } from "./types";
import { getNativeClient } from "./connection";
import * as schema from "../db/schema";
// Get the database client
const dbClient = await getNativeClient();
if (!dbClient) throw new Error("Database client initialization failed");
export const auth = betterAuth({
database: drizzleAdapter(dbClient, {
provider: "pg",
schema
}),
plugins: [
admin(),
organization(),
emailOTP({
async sendVerificationOTP({ email, otp, type }) {
if (type === "sign-in") {
const result = await sendOTPEmail(email, otp)
if (isFailure(result)) {
console.error(result.error)
}
}
}
})]
});
2 replies