mirror of
https://github.com/LukeHagar/better-auth.git
synced 2025-12-10 04:19:32 +00:00
docs(express): update express router example for v5 (#1681)
Added comments about how to use it with the recently release ExpressJS v5
This commit is contained in:
committed by
GitHub
parent
c3a37cc704
commit
b3361ff6ea
@@ -13,7 +13,7 @@ Note that CommonJS (cjs) isn't supported. Use ECMAScript Modules (ESM) by settin
|
|||||||
|
|
||||||
### Mount the handler
|
### 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).
|
||||||
|
|
||||||
<Callout type="warn">
|
<Callout type="warn">
|
||||||
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".
|
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 app = express();
|
||||||
const port = 3005;
|
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
|
// Mount express json middleware after Better Auth handler
|
||||||
// or only apply it to routes that don't interact with Better Auth
|
// or only apply it to routes that don't interact with Better Auth
|
||||||
|
|||||||
Reference in New Issue
Block a user