Passing user and calling a function between two scripts

I have the main.js script which executes the authenticating function and creates a variable called user.
user = Moralis.User.current();

I have a script.js that follows main.js which has a launch function that checks if a user is logged in and renders a game canvas/dom element.

    let user = Moralis.User.current();
    if (!user){
        console.log("no user");
        //user = await Moralis.Web3.authenticate(); 
    }
    else
    {
        console.log(user.get("ethAddress")+" "+'logged in');
        game = new Phaser.Game(config);
    }
})()```

How do i call the launch function immediately as soon as my user is authenticated. 
Everytime  I log in, the console reads  "no user"

how do you authenticate?

var user;

Moralis.start({ //**// });

async function init() {

user = Moralis.User.current();

console.log(user);

if (user) {

renderGame();

} else {

$("#login_button").click(async () => {

  try {

    user = await Moralis.Web3.authenticate();

    renderGame();

   console.log(user);

  } catch (error) {

    console.log(error);

  }

});

}

}

It triggers a metamask sign in

You can make a button to start the game. It looks like there is a button to authenticate

1 Like