Cloudflare Workers - /auth always returning 404.

Hey, the request is able to entered on the route but better auth always returning 404.

Hono route:
app.all("/auth/*", async (c, next) => { if (c.req.path.startsWith("/auth/")) { // Changed to /auth/ to avoid matching /auth exactly const auth = createAuth(c.env); console.log(Handling auth request: ${c.req.method} ${c.req.path}); try { // const url = new URL(c.req.url); // const adjustedRequest = new Request(url.toString(), { // method: c.req.method, // headers: c.req.header(), // body: c.req.raw.body, // }); const response = await auth.handler(c.req.raw); console.log(Auth response status: ${response.status}); return response; } catch (error: any) { console.error("Auth error:", error); return c.json({ error: error.message }, 500);Í } } return next(); });

Here is my config:
export function createAuth(env: any) { return betterAuth({ database: drizzleAdapter(createDB(env.DB), { schema: schemas, provider: "sqlite", }), emailAndPassword: { enabled: false, }, socialProviders: { google: { clientId: env.GOOGLE_CLIENT_ID, clientSecret: env.GOOGLE_CLIENT_SECRET, }, }, baseURL: env.BASE_URL || "http://localhost:8787", basePath: "/auth", session: { expiresIn: 60 * 60 * 24 * 7, // 7 days updateAge: 60 * 60 * 24, // 1 day, }, secret: env.JWT_SECRET, }); }
Better-auth response:


Libraries:
"better-auth": "^1.2.8"
"hono": "^4.7.11"
image.png
Solution
this is how i do it

app.on(["POST", "GET"], "/api/auth/**", (c) => { const envi = env(c) return auth(envi).handler(c.req.raw) });
Was this page helpful?