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"
No description
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)...
Jump to solution
5 Replies
Tamada
TamadaOP3mo ago
Hi @Ping , could you please, assist me here? been stuck here for more than a day. been talking to gpt, claude, and read the documentation but nothing helps.
Tamada
TamadaOP3mo ago
No description
mdchad
mdchad3mo ago
can you try app.on instead of .all?
Solution
mdchad
mdchad3mo ago
this is how i do it app.on(["POST", "GET"], "/api/auth/**", (c) => { const envi = env(c) return auth(envi).handler(c.req.raw) });
Tamada
TamadaOP3mo ago
Yep, is now ok. it seems like I missed the documentation about strictly using their client sdk to able to access to the auth endpoints.

Did you find this page helpful?