簡體   English   中英

如何將路由值傳遞給我的 Prisma function?

[英]How do I pass on routed values to my Prisma function?

我的目標是將登錄數據(用戶輸入)傳遞給 function,其中 Prisma“搜索”數據庫中的相應條目。 當前代碼涉及 4 個不同的類(不確定在這種情況下是否就是它們所稱的)

I. Login.jsx 獲取輸入並將其傳遞給前端 API

 async function handleLogin() {
    const suc = await Api.login(username, password);

  }

二。 Api.ts 使用此數據發送 axios post 請求

const url = 'http://localhost:8080';

async function login(username, password) {
    console.log(username, password, url);
    console.log("Log message of FE-API: " + username);
    const response = await axios.post(`${url}/user/login`, {
        e_mail: username,
        password: password
    });
    console.log(response);
    return response.status === 200;
}

三、 users.js 使用 express js 並將數據發布到 PrismaApi

router.post('/login', async function (req) {
  console.log("Log message of user: " + req);
  const loggedIn = await Api.login(req);
  res.status(loggedIn ? 200 : 400).send();
})

四、 PrismaApi.js 應該帶這些參數來搜索相應的條目

async function login(e_mail) {
    console.log("Log message of PrismaApi: " + e_mail); 
    const loginCreds = await prisma.nutzer.findFirst({
        where: {
          email: e_mail,
        },

});
    return !!loginCreds;
} 

錯誤日志:

\backend\node_modules\@prisma\client\runtime\index.js:32881
    if (!Object.prototype.hasOwnProperty.call(object, key)) {
                                         ^

RangeError: Maximum call stack size exceeded
    at BufferList.hasOwnProperty (<anonymous>)
    at getDepth (D:\(a) Coding\Repositories\b3\backend\node_modules\@prisma\client\runtime\index.js:32881:42)
    at getDepth (D:\(a) Coding\Repositories\b3\backend\node_modules\@prisma\client\runtime\index.js:32885:21)
    at getDepth (D:\(a) Coding\Repositories\b3\backend\node_modules\@prisma\client\runtime\index.js:32885:21)
    at getDepth (D:\(a) Coding\Repositories\b3\backend\node_modules\@prisma\client\runtime\in    at getDepth (D:\(a) Coding\Repositories\b3\backend\node_modules\@prisma\client\runtime\index.js:32885:21)
    at getDepth (D:\(a) Coding\Repositories\b3\backend\node_modules\@prisma\client\runtime\index.js:32885:21)
    at getDepth (D:\(a) Coding\Repositories\b3\backend\node_modules\@prisma\client\runtime\index.js:32885:21)
    at getDepth (D:\(a) Coding\Repositories\b3\backend\node_modules\@prisma\client\runtime\index.js:32885:21)
    at getDepth (D:\(a) Coding\Repositories\b3\backend\node_modules\@prisma\client\runtime\index.js:32885:21) {
  clientVersion: '4.6.1'
}

在同時使用 email 和密碼之前,我目前僅通過電子郵件嘗試使用此代碼來測試工作流程。 我期待一個代碼來查看登錄過程是否成功,但我只收到來自 prisma 模塊的錯誤消息,所以我猜 Prisma 沒有得到正確的輸入。

經過更多研究后解決了問題,我需要后端 app.js 中的bodyParser

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM