diff --git a/docs/content/docs/integrations/express.mdx b/docs/content/docs/integrations/express.mdx index d4b3e7d7..9232d130 100644 --- a/docs/content/docs/integrations/express.mdx +++ b/docs/content/docs/integrations/express.mdx @@ -13,7 +13,7 @@ Note that CommonJS (cjs) isn't supported. Use ECMAScript Modules (ESM) by settin ### Mount the handler -To enable Better Auth to handle requests, we need to mount the handler to an API route. Create a catch-all route to manage all requests to `/api/auth/*` (or any other path specified in your Better Auth options). +To enable Better Auth to handle requests, we need to mount the handler to an API route. Create a catch-all route to manage all requests to `/api/auth/*` in case of ExpressJS v4 or `/api/auth/*splat` in case of ExpressJS v5 (or any other path specified in your Better Auth options). Don’t use `express.json()` before the Better Auth handler. Use it only for other routes, or the client API will get stuck on "pending". @@ -27,7 +27,8 @@ import { auth } from "./auth"; const app = express(); const port = 3005; -app.all("/api/auth/*", toNodeHandler(auth)); +app.all("/api/auth/*", toNodeHandler(auth)); // For ExpressJS v4 +// app.all("/api/auth/*splat", toNodeHandler(auth)); For ExpressJS v5 // Mount express json middleware after Better Auth handler // or only apply it to routes that don't interact with Better Auth