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

356
Vistas
My terminal hangs after promise.all resolves, why?

Hi I am using Firebase for backend and I want to understand why this is just hanging in the terminal.

I am trying to seed my Authentication list and my Firestore db, so I created a seeding script. I read a list of users from a JSON file, and then I add them to Auth, however, in order to create a matching user record in Firestore, I retain the user ID that is returned to me from createUserWithEmailAndPassword to create a user object with first_name and last_name (trivial attributes).

Afterwards, I return that user object, and resolve all promises with Promise.all and then continue to use setDoc to add each of those user objects to Firestore.

Note: both of these promise arrays are created using map functions across the initial user list from JSON and then across the returned user object list from Auth, respectively.

The key point here is, even though everything is added to my Auth and Firestore just fine... the terminal stays hanging, to no avail...

const { store, auth } = require('../config.js');
const { createUserWithEmailAndPassword } = require('firebase/auth');
const { doc, setDoc } = require('firebase/firestore');

const data = require("./SEED_DATA.json");

console.log(data ? "DATA PRESENT" : "")

const seedUsers = async (users) => {
  // seeds firebase Auth
  const user_auth_hydrated = await Promise.all(users.map(user => {
    return createUserInAuth(user)
  }))

  // seeds firebase Firestore
  // we wait for auth because we want to retain the uids to create matching records in store
  const user_store = await Promise.all(user_auth_hydrated.map(user => {
    return createUserInStore(user)
  }))

  Promise.resolve(user_store)
}

const createUserInAuth = async ({first_name, last_name, email, password}) => {
  return await createUserWithEmailAndPassword(auth, email, password)
  .then((userCredential) => {
    // Signed in 
    const {uid} = userCredential.user;
    return {
      ID: uid.toString(),
      FIRSTNAME: first_name,
      LASTNAME: last_name
    }
  })
  .catch(err => console.log("USER ADD AUTH FAILED", err.code, err.message))
}

const createUserInStore = async ({ID, FIRSTNAME, LASTNAME}) => {
  return await setDoc(doc(store, 'users', ID), {FIRSTNAME, LASTNAME})
}

seedUsers(data);

Picture of terminal just hanging post execution (everything is fine in Auth and Firestore): enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You shouldn't mix traditional approach of promises and async / await syntax together. I advise to stick with async / await only.

The seedUsers async function returns undefined. Doing Promise.resolve(user_store) does nothing except creating an object that is destroyed at the end of the function.

You should fix your code as follows:

const seedUsers = async (users) => {
  /* your logic */
  return user_store;
}

and


const createUserInAuth = async ({first_name, last_name, email, password}) => {
  try {
    const userCredential = await createUserWithEmailAndPassword(auth, email, password);
    /* your return logic */
  } catch (error) {
    /* your error logic */
  }
}
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