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

118
Visualizações
How to export a user variable

I have some google user information that I want to export as it is async I have an async function that works well the problem is that the second module is not getting it despite I created an async function waiting for it. Please help of course I am new. Moldule 1:

  export async function setU (u) {
     
    let user= await u; 
    console.log(user.uid)        
    return user   
}

This gets the info without problem, the problem is when importing.

   import {login,cerrar,setU} from '/js/log_principal.js'

The next function in module 2 does not work. Module:2

       login() 

  //getInfo(datos)
  
  b(setU)   

async function b(usuario){    
   
    let user= await usuario;        
   console.log(user.uid) // this gives undefined!!! :(


    
}


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

0

I think you are not understanding correctly what you import when importing a function.

What you do here is passing a function (which is not executed) thru a different function like:

function demonstration(await function user() {}) {
  // code...
}

instead you first want to execute the function and then pass it thru the function

The solution is quite simple

File1.js

export async function setU (u) {
  let user = await u; 
  console.log(user.uid);     
  return user;
}

File2.js

import {login,cerrar,setU} from '/js/log_principal.js'

login() 

b(setU)   

async function b(usuario){
  let user= await usuario;        
  console.log(user.uid);
}
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