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

241
Visualizações
Unable to extract resolved value from async function

I've created a function to get the current user's data from the Reddit API, as part of a Reddit object with multiple functions.

async getCurrentUserId() {
        if (userID) return userID;

        const token = await Reddit.getAccessToken().then(val => {
            return val;
        })
        const url = "https://oauth.reddit.com/api/v1/me"
        const headers = {
            "Authorization": `Bearer ${token}`,
            "User-Agent": "blablabla",
        };

        const response = await fetch(url, { headers: headers });
        if (response.ok) {
            const jsonResponse = await response.json();
            return jsonResponse.name;
        }
    },

However, when I try and extract the data, I keep getting a promise rather than the resolved value, and I can't seem to be able to figure it out.

const userID = Reddit.getCurrentUserId().then(val => {
  return val;
}) // returns "Promise {<pending>}"

Assistance with this would be appreciated.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You either need to do your logic inside .then(), or simplify by using await:

const token = await Reddit.getAccessToken();

...

const userID = await Reddit.getCurrentUserId();
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