vendredi 26 février 2021

accessing updated variables outside of .then [duplicate]

I have the code below:

let auth = '';
Data.loginRedirect(auth)
        .then(response => {
        this.var = response.data;   
        auth= this.var;
        console.log(auth); //outputs array
        })
      console.log(auth); //outputs nothing ''

      if ((auth) != '') {
        alert('Email already used!');
      }

In this code, I need auth to be updated with the array value after LoginRedirect runs to use in the if statement. How can I do this?

Aucun commentaire:

Enregistrer un commentaire