Integrations
Hono
Using Hono with Convex + Better Auth
If you prefer to work with Hono instead of the default
HttpRouter, Hono can replace the default authComponent.registerRoutes()
method. Check out the Convex w/ Hono Stack
article and
the Better Auth Hono docs
for more details.
You'll need to install the convex-helpers
package if you haven't already.
Configuration
import { Hono } from "hono";
import { HonoWithConvex, HttpRouterWithHono } from "convex-helpers/server/hono";
import { ActionCtx } from "./_generated/server";
import { createAuth } from "./auth";
const app: HonoWithConvex<ActionCtx> = new Hono();
// Redirect root well-known to api well-known
app.get("/.well-known/openid-configuration", async (c) => {
return c.redirect("/api/auth/convex/.well-known/openid-configuration");
});
app.on(["POST", "GET"], "/api/auth/*", async (c) => {
const auth = createAuth(c.env);
return auth.handler(c.req.raw);
});
const http = new HttpRouterWithHono(app);
export default http;
Add CORS support
Required for client only / SPA installs like React/Vite.
import { Hono } from "hono";
import { HonoWithConvex, HttpRouterWithHono } from "convex-helpers/server/hono";
import { cors } from "hono/cors";
import { ActionCtx } from "./_generated/server";
import { createAuth } from "../lib/auth";
const app: HonoWithConvex<ActionCtx> = new Hono();
app.use(
"/api/auth/*",
cors({
origin: process.env.SITE_URL,
allowHeaders: ["Content-Type", "Authorization", "Better-Auth-Cookie"],
allowMethods: ["GET", "POST", "OPTIONS"],
exposeHeaders: ["Content-Length", "Set-Better-Auth-Cookie"],
maxAge: 600,
credentials: true,
})
);
// ...