Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

208
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda