From b3361ff6eae11ef5dff64c06eb02e56896f70ca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Cervera=20Claudio?= <293444+angelcervera@users.noreply.github.com> Date: Thu, 6 Mar 2025 12:42:36 +0000 Subject: [PATCH] docs(express): update express router example for v5 (#1681) Added comments about how to use it with the recently release ExpressJS v5 --- docs/content/docs/integrations/express.mdx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/content/docs/integrations/express.mdx b/docs/content/docs/integrations/express.mdx index d4b3e7d721..9232d1309f 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