Home > front end >  How do I pass on routed values to my Prisma function?
How do I pass on routed values to my Prisma function?

Time:12-01

My goal is to pass log in data (user input) on to a function in which Prisma 'searches' the database for corresponding entries. The current code involves 4 different classes (not sure if that's what they're called in this context)

I. Login.jsx takes the input and passes it on to the Frontend API

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

  }

II. Api.ts sends a axios post request with this data

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;
}

III. users.js makes use of express js and posts the data to the 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();
})

IV. PrismaApi.js should take these parameters to search for the corresponding entry

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;
} 

Error-log:

\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'
}

I tried this code with E-Mail only at the moment to test the workflow before using both email and password. I was expecting a code to see whether the login process was successful, but I'm only receiving error messages from the prisma modules so I guess Prisma is not getting the right input.

CodePudding user response:

Solved the problem after some more research, I needed the bodyParser inside of my backend app.js

  • Related