Request Keeps Pending (Express.js)

im using next.js for frontend and express for backend, why it keeps pending when i'm doing sign up with email and password?
No description
6 Replies
Imam
ImamOP5mo ago
Imam
ImamOP5mo ago
here is the codes
No description
No description
No description
bekacru
bekacru5mo ago
if you use express.json middleware it's gonna parse the body before it gets to the handler which mean it'd the read the body before the auth handler can get to it. If you remove that, it should work. Just apply the middleware to paths not handled by Better Auth.
Imam
ImamOP5mo ago
Just apply the middleware to paths not handled by Better Auth. sorry, how to do this, can you give me example? i've never doing that before
bekacru
bekacru5mo ago
not super familiar but I think the easiest way to do this is to put the handler before you mount the middleware. (not sure if this is the best approach)
app.all("/api/auth", toNodeHandler(auth))
app.use(express.json()
app.all("/api/auth", toNodeHandler(auth))
app.use(express.json()
Imam
ImamOP5mo ago
ok i'll try it, i'll let you know my progress, thanks for your fast response, really appreciate it this is how i did and its working!
app.use((req, res, next) => {
if (!req.path.startsWith('/api/auth/')) {
express.json()(req, res, next);
} else {
next();
}
});
app.use((req, res, next) => {
if (!req.path.startsWith('/api/auth/')) {
express.json()(req, res, next);
} else {
next();
}
});

Did you find this page helpful?