Error in signing up using cloudflare d1 database and drizzle orm on nextjs15

I've been trying to make the signup logic work, ive watch so 2 tutorials relating to the same techstack as mine and wrote same code as them but mine doesn't work at all gave same errors on all iterations. this error occurs when i submit the sign-up form, i have nothing in the code defined as "fullSchema" :
ERROR TypeError Cannot read properties of undefined (reading 'fullSchema') Better Auth

at y (.next\server\chunks\node_modules_better-auth_dist_37bdef._.js:5192:33)
(... clipped)
at async Server.requestListener (node_modules\next\dist\server\lib\start-server.js:146:13)

POST /api/auth/sign-up/email?currentURL=http%3A%2F%2Flocalhost%3A3000%2Fregister 500 in 135ms
ERROR TypeError Cannot read properties of undefined (reading 'fullSchema') Better Auth

at y (.next\server\chunks\node_modules_better-auth_dist_37bdef._.js:5192:33)
(... clipped)
at async Server.requestListener (node_modules\next\dist\server\lib\start-server.js:146:13)

POST /api/auth/sign-up/email?currentURL=http%3A%2F%2Flocalhost%3A3000%2Fregister 500 in 135ms
and this error appears in the browser console:
{
"response": {},
"request": {
"baseURL": "http://localhost:3000/api/auth",
"credentials": "include",
"method": "POST",
"plugins": [
{
"id": "redirect",
"name": "Redirect",
"hooks": {}
},
{
"id": "add-current-url",
"name": "Add current URL",
"hooks": {}
},
{
"id": "apply-schema",
"name": "Apply Schema",
"version": "1.0.0"
}
],
"body": "{\"name\":\"dev\",\"email\":\"[email protected]\",\"password\":\"qwerty1234\",\"callbackURL\":\"/verify-email\"}",
"url": "http://localhost:3000/api/auth/sign-up/email?currentURL=http%3A%2F%2Flocalhost%3A3000%2Fsign-up",
"headers": {},
"signal": {}
},
"error": {
"status": 500,
"statusText": "Internal Server Error"
}
}
{
"response": {},
"request": {
"baseURL": "http://localhost:3000/api/auth",
"credentials": "include",
"method": "POST",
"plugins": [
{
"id": "redirect",
"name": "Redirect",
"hooks": {}
},
{
"id": "add-current-url",
"name": "Add current URL",
"hooks": {}
},
{
"id": "apply-schema",
"name": "Apply Schema",
"version": "1.0.0"
}
],
"body": "{\"name\":\"dev\",\"email\":\"[email protected]\",\"password\":\"qwerty1234\",\"callbackURL\":\"/verify-email\"}",
"url": "http://localhost:3000/api/auth/sign-up/email?currentURL=http%3A%2F%2Flocalhost%3A3000%2Fsign-up",
"headers": {},
"signal": {}
},
"error": {
"status": 500,
"statusText": "Internal Server Error"
}
}
versions: "better-auth": "^1.0.22" "next": "15.1.0" "drizzle-orm": "^0.38.2" "wrangler": "^3.98.0" any help is appreciated!
8 Replies
Dev
DevOP3mo ago
im using the schema generated by the command mentioned in the docs i.e. npx @better-auth/cli generate @/lib/auth.ts
export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: "sqlite",
}),
plugins: [openAPI()],
emailAndPassword: {
enabled: true,
requireEmailVerification: false,
},
socialProviders: {
google: {
clientId: process.env.GOOGLE_CLIENT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
},
},
});
export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: "sqlite",
}),
plugins: [openAPI()],
emailAndPassword: {
enabled: true,
requireEmailVerification: false,
},
socialProviders: {
google: {
clientId: process.env.GOOGLE_CLIENT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
},
},
});
@/lib/auth-client.ts
import { createAuthClient } from "better-auth/react";

export const authClient = createAuthClient({
baseURL: process.env.BETTER_AUTH_URL!,
});

export const { signIn, signOut, signUp, useSession } = authClient;
import { createAuthClient } from "better-auth/react";

export const authClient = createAuthClient({
baseURL: process.env.BETTER_AUTH_URL!,
});

export const { signIn, signOut, signUp, useSession } = authClient;
the sign-up method im using:
const onSubmit = async (values: z.infer<typeof signUpSchema>) => {
const { name, email, password } = values;
const { data, error } = await signUp.email(
{
name,
email,
password,
callbackURL: "/verify-email",
},
{
onRequest: () => {
setPending(true);
},
onResponse: () => {
setPending(false);
},
onSuccess: () => {
toast.success("Account created", {
description:
"Your account has been created. Check your email for a verification link.",
});
},
onError: (ctx) => {
console.log("Unexpected Error: ", ctx);
toast.error("Something went wrong", {
description:
ctx.error.message ?? "Something went wrong.",
});
},
},
);
};
const onSubmit = async (values: z.infer<typeof signUpSchema>) => {
const { name, email, password } = values;
const { data, error } = await signUp.email(
{
name,
email,
password,
callbackURL: "/verify-email",
},
{
onRequest: () => {
setPending(true);
},
onResponse: () => {
setPending(false);
},
onSuccess: () => {
toast.success("Account created", {
description:
"Your account has been created. Check your email for a verification link.",
});
},
onError: (ctx) => {
console.log("Unexpected Error: ", ctx);
toast.error("Something went wrong", {
description:
ctx.error.message ?? "Something went wrong.",
});
},
},
);
};
bekacru
bekacru3mo ago
pass the schema on the drizzle adapter
drizzleAdapter(db, {
schema: {
user: schema.user,
account: schema.account,
session: schema.session,
verification: schema.verification
//...
}
})
drizzleAdapter(db, {
schema: {
user: schema.user,
account: schema.account,
session: schema.session,
verification: schema.verification
//...
}
})
Dev
DevOP3mo ago
still doesnt work, just the error message is new
ERROR TypeError e.select is not a function Better Auth

at Object.findOne (.next\server\chunks\node_modules_better-auth_dist_37bdef._.js:5287:95)
at Object.findUserByEmail (node_modules\next\dist\compiled\next-server\app-route.runtime.dev.js:10:32804)
at async AppRouteRouteModule.handle
at async Server.requestListener (node_modules\next\dist\server\lib\start-server.js:146:13)

POST /api/auth/sign-up/email?currentURL=http%3A%2F%2Flocalhost%3A3000%2Fsign-up 500 in 3050ms
ERROR TypeError e.select is not a function Better Auth

at Object.findOne (.next\server\chunks\node_modules_better-auth_dist_37bdef._.js:5287:95)
at Object.findUserByEmail (node_modules\next\dist\compiled\next-server\app-route.runtime.dev.js:10:32804)
at async AppRouteRouteModule.handle
at async Server.requestListener (node_modules\next\dist\server\lib\start-server.js:146:13)

POST /api/auth/sign-up/email?currentURL=http%3A%2F%2Flocalhost%3A3000%2Fsign-up 500 in 3050ms
i know im making some silly mistake somewhere but this is such a pain
bekacru
bekacru3mo ago
this is saying db.select isn't a function are you sure your drizzle db intance is properly initalized?
Dev
DevOP3mo ago
this is what i currently have in the drizzle instance
import { drizzle, DrizzleD1Database } from "drizzle-orm/d1";
import * as schema from "./schema";

interface Env {
DB: DrizzleD1Database;
}

export const db = (env: Env) => drizzle(env.DB, { schema });

export function createD1Client(env: Env) {
return db(env);
}
import { drizzle, DrizzleD1Database } from "drizzle-orm/d1";
import * as schema from "./schema";

interface Env {
DB: DrizzleD1Database;
}

export const db = (env: Env) => drizzle(env.DB, { schema });

export function createD1Client(env: Env) {
return db(env);
}
i couldnt find any resource regarding it so took help from claude and came up with this
bekacru
bekacru3mo ago
cf setup requires a bit of work around. If you're just trying out stuff don't use CF try something else
bekacru
bekacru3mo ago
but if you need to use CF for some specefic reason check out this example as a starting point https://github.com/Bekacru/better-auth-nextjs-cf-d1-example
GitHub
GitHub - Bekacru/better-auth-nextjs-cf-d1-example
Contribute to Bekacru/better-auth-nextjs-cf-d1-example development by creating an account on GitHub.
Dev
DevOP3mo ago
thanks, will look into it

Did you find this page helpful?