Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

214
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda