You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将路由传递的值传入Prisma函数?登录流程栈溢出排查

Solution

The maximum call stack overflow error occurs because you’re passing the entire Express req object to your Prisma login function instead of extracting the email from the request body. Here’s how to fix the data flow:

Step 1: Correct the Express Route Handler (users.js)

Your current code sends the full request object to Prisma, which triggers recursive processing of the large, nested req structure. Instead, extract the email from req.body and pass only that string to Prisma:

router.post('/login', async function (req, res) { // Ensure both req and res are included as parameters
  const { e_mail } = req.body; // Extract email from the JSON request body
  
  // Critical: Add this to your main Express app file if missing (to parse JSON bodies)
  // app.use(express.json());

  console.log("Log message of user: " + e_mail);
  const loggedIn = await Api.login(e_mail);
  res.status(loggedIn ? 200 : 400).send();
})

Add a quick check to ensure you’re receiving a valid string before querying the database:

async function login(e_mail) {
  if (!e_mail || typeof e_mail !== 'string') {
    console.error("Invalid email received:", e_mail);
    return false;
  }
  
  console.log("Log message of PrismaApi: " + e_mail); 
  const loginCreds = await prisma.nutzer.findFirst({
    where: {
      email: e_mail,
    },
  });
  return !!loginCreds;
} 

Step 3: Confirm Frontend Data Flow

Your frontend API (Api.ts) is correctly sending the e_mail field, so no changes are needed there. Once the email flow works, you can extend the logic to include password validation.

Root Cause of the Error

When you pass the entire req object to Prisma, it tries to traverse all nested properties of the request (headers, socket connections, etc.) recursively. This triggers infinite recursion in Prisma’s internal getDepth function, leading to the stack overflow.


内容的提问来源于stack exchange,提问作者GoethesRevenge

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 03:21:10