Home > Net >  How to export a user variable
How to export a user variable

Time:10-22

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!!! :(


    
}


    

CodePudding user response:

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);
}
  • Related