[GH-ISSUE #300] Cannot read properties of undefined (reading 'query') #8209

Closed
opened 2026-04-13 03:18:43 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @darklight9811 on GitHub (Oct 23, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/300

Describe the bug
When trying to use better-auth with hono and drizzle, it throws Cannot read properties of undefined (reading 'query')

To Reproduce
Steps to reproduce the behavior:

import { serve } from "@hono/node-server";
import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { drizzle } from "drizzle-orm/node-postgres";
import {
  boolean,
  integer,
  pgTable,
  timestamp,
  varchar,
} from "drizzle-orm/pg-core";
import { Hono } from "hono";

export const db = drizzle(process.env.DATABASE_URL as any);

const usersTable = pgTable("users", {
  id: integer().primaryKey().generatedAlwaysAsIdentity(),

  name: varchar({ length: 255 }).notNull(),
  image: varchar({ length: 255 }),
  email: varchar({ length: 255 }).notNull().unique(),
  emailVerified: boolean().default(false),

  createdAt: timestamp().notNull().defaultNow(),
  updatedAt: timestamp(),
});

const sessionsTable = pgTable("sessions", {
  id: integer().primaryKey().generatedAlwaysAsIdentity(),

  userId: integer().notNull(),

  ipAddress: varchar({ length: 40 }),
  userAgent: varchar({ length: 255 }),

  createdAt: timestamp().notNull().defaultNow(),
  expiresAt: timestamp().notNull(),
});

const accountsTable = pgTable("accounts", {
  id: integer().primaryKey().generatedAlwaysAsIdentity(),

  userId: integer().notNull(),
  accountId: integer().notNull(),
  providerId: varchar({ length: 255 }).notNull(),

  accessToken: varchar({ length: 255 }),
  refreshToken: varchar({ length: 255 }),
  password: varchar({ length: 255 }),

  createdAt: timestamp().notNull().defaultNow(),
  expiresAt: timestamp().notNull(),
});

const verificationsTable = pgTable("sessions", {
  id: integer().primaryKey().generatedAlwaysAsIdentity(),

  identifier: varchar({ length: 255 }).notNull(),
  value: varchar({ length: 255 }).notNull(),

  createdAt: timestamp().notNull().defaultNow(),
  expiresAt: timestamp().notNull(),
});

const auth = betterAuth({
  baseURL: "http://localhost:6006/auth",
  secret: "aisdjaisdhafdsf",
  database: drizzleAdapter(db, {
    provider: "pg",
    usePlural: true,
    schema: {
      users: usersTable,
      accounts: accountsTable,
      sessions: sessionsTable,
      verifications: verificationsTable,
    },
  }),
  emailAndPassword: {
    enabled: true,
  },
});

const app = new Hono();
app.on(["POST", "GET"], "/auth/**", (c) => auth.handler(c.req.raw));
serve({
  fetch: app.fetch,
  port: 6006,
});

Expected behavior
For the auth methods to work

Screenshots
image

Desktop (please complete the following information):

  • OS: windows 10
  • Browser postman
  • Version 11.18
Originally created by @darklight9811 on GitHub (Oct 23, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/300 **Describe the bug** When trying to use better-auth with hono and drizzle, it throws `Cannot read properties of undefined (reading 'query')` **To Reproduce** Steps to reproduce the behavior: ``` typescript import { serve } from "@hono/node-server"; import { betterAuth } from "better-auth"; import { drizzleAdapter } from "better-auth/adapters/drizzle"; import { drizzle } from "drizzle-orm/node-postgres"; import { boolean, integer, pgTable, timestamp, varchar, } from "drizzle-orm/pg-core"; import { Hono } from "hono"; export const db = drizzle(process.env.DATABASE_URL as any); const usersTable = pgTable("users", { id: integer().primaryKey().generatedAlwaysAsIdentity(), name: varchar({ length: 255 }).notNull(), image: varchar({ length: 255 }), email: varchar({ length: 255 }).notNull().unique(), emailVerified: boolean().default(false), createdAt: timestamp().notNull().defaultNow(), updatedAt: timestamp(), }); const sessionsTable = pgTable("sessions", { id: integer().primaryKey().generatedAlwaysAsIdentity(), userId: integer().notNull(), ipAddress: varchar({ length: 40 }), userAgent: varchar({ length: 255 }), createdAt: timestamp().notNull().defaultNow(), expiresAt: timestamp().notNull(), }); const accountsTable = pgTable("accounts", { id: integer().primaryKey().generatedAlwaysAsIdentity(), userId: integer().notNull(), accountId: integer().notNull(), providerId: varchar({ length: 255 }).notNull(), accessToken: varchar({ length: 255 }), refreshToken: varchar({ length: 255 }), password: varchar({ length: 255 }), createdAt: timestamp().notNull().defaultNow(), expiresAt: timestamp().notNull(), }); const verificationsTable = pgTable("sessions", { id: integer().primaryKey().generatedAlwaysAsIdentity(), identifier: varchar({ length: 255 }).notNull(), value: varchar({ length: 255 }).notNull(), createdAt: timestamp().notNull().defaultNow(), expiresAt: timestamp().notNull(), }); const auth = betterAuth({ baseURL: "http://localhost:6006/auth", secret: "aisdjaisdhafdsf", database: drizzleAdapter(db, { provider: "pg", usePlural: true, schema: { users: usersTable, accounts: accountsTable, sessions: sessionsTable, verifications: verificationsTable, }, }), emailAndPassword: { enabled: true, }, }); const app = new Hono(); app.on(["POST", "GET"], "/auth/**", (c) => auth.handler(c.req.raw)); serve({ fetch: app.fetch, port: 6006, }); ``` **Expected behavior** For the auth methods to work **Screenshots** ![image](https://github.com/user-attachments/assets/1483f1c3-734a-4965-a162-24264b531c61) **Desktop (please complete the following information):** - OS: windows 10 - Browser postman - Version 11.18
GiteaMirror added the locked label 2026-04-13 03:18:43 -05:00
Author
Owner

@Bekacru commented on GitHub (Oct 23, 2024):

First, you shouldn't use integers as IDs. Better Auth expects all IDs to be strings. And, the session ID serves as the session token, so it should never be something you assign manually.

<!-- gh-comment-id:2430904824 --> @Bekacru commented on GitHub (Oct 23, 2024): First, you shouldn't use integers as IDs. Better Auth expects all IDs to be strings. And, the session ID serves as the session token, so it should never be something you assign manually.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8209