Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

207
Views
NextAuth fetching api endpoint - req.body undefined

i'm trying to use NextAuthJS for authentication in my NextJS app..

I'm using this following code from documentation

  authorize: async(credentials, req)=>{
    const res = await fetch("http://localhost:3000/api/userverify",{
      method: 'POST',
      credentials: "include",
      body: JSON.stringify(credentials),
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
      },
    })
    const user = await res.json()

    if(res.ok && user){
      return user
    }
    return null
  }

the problem is the actual fetching, in the userverify.js i have this code:

export default async function verify(res, req){
  const credentials = req.body
  console.log(credentials)
  const user = await findUser(credentials.email)
  if(user){
    if(await argon2.verify(req.body.password, user.password)){
      res.status(200).send(user)
      return user
    }
    else{
      res.status(401).send("Credentials Incorrect")
    }
  }
}

req.body in this file is undefined, im not using express only nextjs built in api routes..

What can i do?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I think it is the order of arguments. did you try logging req and res. First argument is request and second is response:

export default async function verify(req, res){

Docs

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!