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

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

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 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