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

301
Visualizações
I'm trying to get a token from API login, but I get an Object null prototype

I am implementing API login with node js and javascript. I'm trying to get a token, but the console says Object: null prototype as shown below.

  [Symbol(Response internals)]: {
    url: 'https://URL(sensitive information)',
    status: 200,
    statusText: 'OK',
    headers: Headers { [Symbol(map)]: [Object: null prototype] },
    counter: 0
  }
}

Below is my code.

export const startKakaoLogin = (req, res) => {
  const baseUrl = "https://kauth.kakao.com/oauth/authorize?";
  const config = {
    client_id: process.env.KA_ID,
    redirect_uri: process.env.KA_RE,
    response_type: "code",
    prompt: "login",
  };
  const params = new URLSearchParams(config).toString();
  const finalUrl = `${baseUrl}&${params}`;
  return res.redirect(finalUrl);
};


export const finishKakaoLogin = async (req, res) => {
  const baseUrl = "https://kauth.kakao.com/oauth/token";
  const config = {
    grant_type: "authorization_code",
    client_id: process.env.KA_ID,
    redirect_uri: process.env.KA_RE,
    code: req.query.code,
  };
  const params = new URLSearchParams(config).toString();
  const finalUrl = `${baseUrl}&${params}`;
  const tokenRequest = await fetch(finalUrl, {
    method: "POST",
    headers: {
      Accept: "application/x-www-form-urlencoded;charset=utf-8",
    },
    body: finalUrl,
  });
  console.log(tokenRequest);
};

Additionally, In the reference, 'curl' was used, but I used 'fetch', did I do something wrong?

POST /oauth/token HTTP/1.1
Host: kauth.kakao.com
Content-type: application/x-www-form-urlencoded;charset=utf-8

curl -v -X POST "https://kauth.kakao.com/oauth/token" \
 -H "Content-Type: application/x-www-form-urlencoded" \
 -d "grant_type=authorization_code" \
 -d "client_id=${REST_API_KEY}" \
 --data-urlencode "redirect_uri=${REDIRECT_URI}" \
 -d "code=${AUTHORIZE_CODE}"
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

What are you expecting to get from the endpoint? You're just logging the Response object right now and are seeing a representation of its internals.

To get e.g. the text from the response body, you'll need to parse it too, here with Response#text():

const text = await tokenRequest.text();
console.log(text);

If you're looking for JSON, then use Response#json().

const data = await tokenRequest.json();
console.log(data);

Be sure to check that the response's error code is what you expect, though, with e.g. tokenRequest.ok.

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