ERROR [Better Auth]: Error Error: NOT_FOUND

api-1 | 2025-05-05T18:47:57.241Z INFO [Better Auth]: Auth initialized
api-1 | [18:47:57.242] INFO (38): Starting server on port 80
api-1 | auth handler http://auth.localhost/auth/get-session <- this is the requset I get
api-1 | 2025-05-05T18:48:09.551Z ERROR [Better Auth]: Error Error: NOT_FOUND
api-1 | at processRequest (file:///app/node_modules/.pnpm/[email protected]/node_modules/better-call/dist/index.js:4833:25)
api-1 | at handler (file:///app/node_modules/.pnpm/[email protected]/node_modules/better-call/dist/index.js:4897:25)
api-1 | at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
api-1 | at async dispatch (file:///app/node_modules/.pnpm/[email protected]/node_modules/hono/dist/compose.js:22:17)
api-1 | at async dispatch (file:///app/node_modules/.pnpm/[email protected]/node_modules/hono/dist/compose.js:22:17)
api-1 | at async file:///app/node_modules/.pnpm/[email protected]/node_modules/hono/dist/hono-base.js:198:25
api-1 | at async responseViaResponseObject (file:///app/node_modules/.pnpm/@[email protected][email protected]/node_modules/@hono/node-server/dist/index.mjs:372:13)
api-1 | at async Server.<anonymous> (file:///app/node_modules/.pnpm/@[email protected][email protected]/node_modules/@hono/node-server/dist/index.mjs:467:14)
api-1 | 2025-05-05T18:47:57.241Z INFO [Better Auth]: Auth initialized
api-1 | [18:47:57.242] INFO (38): Starting server on port 80
api-1 | auth handler http://auth.localhost/auth/get-session <- this is the requset I get
api-1 | 2025-05-05T18:48:09.551Z ERROR [Better Auth]: Error Error: NOT_FOUND
api-1 | at processRequest (file:///app/node_modules/.pnpm/[email protected]/node_modules/better-call/dist/index.js:4833:25)
api-1 | at handler (file:///app/node_modules/.pnpm/[email protected]/node_modules/better-call/dist/index.js:4897:25)
api-1 | at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
api-1 | at async dispatch (file:///app/node_modules/.pnpm/[email protected]/node_modules/hono/dist/compose.js:22:17)
api-1 | at async dispatch (file:///app/node_modules/.pnpm/[email protected]/node_modules/hono/dist/compose.js:22:17)
api-1 | at async file:///app/node_modules/.pnpm/[email protected]/node_modules/hono/dist/hono-base.js:198:25
api-1 | at async responseViaResponseObject (file:///app/node_modules/.pnpm/@[email protected][email protected]/node_modules/@hono/node-server/dist/index.mjs:372:13)
api-1 | at async Server.<anonymous> (file:///app/node_modules/.pnpm/@[email protected][email protected]/node_modules/@hono/node-server/dist/index.mjs:467:14)
2 Replies
volks
volksOP4w ago
I am using hono and better auth 1.27
export function initAuth() {
if (authInstance) {
return authInstance;
}

authInstance = betterAuth({
database: drizzleAdapter(getDB(), {
provider: "pg",
schema: {
user: users,
verification: verifications,
account: accounts,
session: sessions,
},
}),
trustedOrigins: ["http://web.localhost"],
emailAndPassword: {
enabled: true,
},
socialProviders: {
twitter: {
clientId: appConfig.twitter.clientId,
clientSecret: appConfig.twitter.clientSecret,
},
},
advanced: {
cookiePrefix: "project",
database: {
generateId: false,
}
},
});

logger.info("Auth initialized");

return authInstance;
}

export function getAuth() {
if (!authInstance) {
throw new Error("Auth not initialized. Call initAuth() first.");
}
return authInstance;
}

export const registerAuth = (app: App) => {
const auth = getAuth();

app.use("*", async (c: Context, next: Next) => {
const session = await auth.api.getSession({ headers: c.req.raw.headers });

if (!session) {
c.set("user", null);
c.set("session", null);
return next();
}

c.set("user", session.user);
c.set("session", session.session);
return next();
});

app.on(["POST", "GET"], "/auth/*", (c) => {
console.log("auth handler", c.req.raw.url);
return auth.handler(c.req.raw);
});
};
export function initAuth() {
if (authInstance) {
return authInstance;
}

authInstance = betterAuth({
database: drizzleAdapter(getDB(), {
provider: "pg",
schema: {
user: users,
verification: verifications,
account: accounts,
session: sessions,
},
}),
trustedOrigins: ["http://web.localhost"],
emailAndPassword: {
enabled: true,
},
socialProviders: {
twitter: {
clientId: appConfig.twitter.clientId,
clientSecret: appConfig.twitter.clientSecret,
},
},
advanced: {
cookiePrefix: "project",
database: {
generateId: false,
}
},
});

logger.info("Auth initialized");

return authInstance;
}

export function getAuth() {
if (!authInstance) {
throw new Error("Auth not initialized. Call initAuth() first.");
}
return authInstance;
}

export const registerAuth = (app: App) => {
const auth = getAuth();

app.use("*", async (c: Context, next: Next) => {
const session = await auth.api.getSession({ headers: c.req.raw.headers });

if (!session) {
c.set("user", null);
c.set("session", null);
return next();
}

c.set("user", session.user);
c.set("session", session.session);
return next();
});

app.on(["POST", "GET"], "/auth/*", (c) => {
console.log("auth handler", c.req.raw.url);
return auth.handler(c.req.raw);
});
};
Debug logs output nothing for drizzle, meaning it does not reach the database it seems. The request does come to the
console.log("auth handler", c.req.raw.url);
return auth.handler(c.req.raw);
console.log("auth handler", c.req.raw.url);
return auth.handler(c.req.raw);
But the auth.handler fails for some reason with a 404 My client config
export const authClient = createAuthClient({
baseURL: config.authUrl,
basePath: "/auth",
plugins: [],
});
export const authClient = createAuthClient({
baseURL: config.authUrl,
basePath: "/auth",
plugins: [],
});
Sergei
Sergei4w ago
I just ran into this. I'm using hono as well. I had to set basePath on the server config

Did you find this page helpful?