BA
Better Auth•5mo ago
Sai Baba

Pending State not getting resolved

I'm trying to use the traditional signup method. But, it is in a pending state forever and not getting resolved. The login method is working. At least, it is immediately returning something. I'm using Next.js for the frontend and Express.js with the backend and drizzle pg for an ORM.
No description
8 Replies
Sai Baba
Sai BabaOP•5mo ago
Update: It is the same for login method too
Sai Baba
Sai BabaOP•5mo ago
I'm getting requests to the backend server. But, something's happening. These requests aren't getting resolved
No description
Ping
Ping•5mo ago
Can you show us how you setup your express server?
Sai Baba
Sai BabaOP•5mo ago
import dotenv from "dotenv"; import express, { Request, Response, NextFunction } from "express"; import cors from "cors"; import { router as contactRouter } from "./routes/contactRoute"; import { toNodeHandler } from "better-auth/node"; import { createDb } from "./db/config"; import { auth } from "./lib/auth"; import { sql } from "drizzle-orm"; dotenv.config(); const app = express(); // Middleware app.use( cors({ origin: "http://localhost:3000", methods: ["GET", "POST", "PUT", "DELETE"], credentials: true, }) ); app.use(express.json()); app.use((req: Request, res: Response, next: NextFunction) => { console.log(req.path, req.method); next(); }); export let db: Awaited<ReturnType<typeof createDb>>; async function startServer() { try { console.log("Attempting to connect to the DB..."); db = await createDb(); await db.execute(sqlSELECT 1); console.log("Connected to the DB successfully 🥳🥳"); // Set up auth routes after DB is initialized app.all("/api/auth/*", toNodeHandler(auth)); app.use("/api/contact", contactRouter); app.listen(process.env.PORT, () => { console.log("Server is running successfully too"); }); } catch (error) { console.error("Failed to start server:", error); process.exit(1); } } startServer(); This is the main file of the backend Even the preflight request returns a 204 - No Content
Ping
Ping•5mo ago
What version of express are you on?
Sai Baba
Sai BabaOP•5mo ago
v4
bekacru
bekacru•5mo ago
Don’t apply json middleware in better auth paths
Sai Baba
Sai BabaOP•5mo ago
Changing "app.use(express.json())' to the start of the middleware would work? Got it Made this change and drizzle was causing some problems Got it sorted now

Did you find this page helpful?