typescript - Lost in asynchronous function. Aways get undefinned -
sorry english. can't head around asynchronous programming! need update node call stoken of user wich variable useraux2. no matter how try undefineed. have read every question , tried many diferrents ways, don't know how set useraux2 = return snapshot.key; (wich btw, snapshot prints ok in console).
i hope can me, don't know else do!
thanks!!
async loginuser(newemail: string, newpassword: string, company: string): firebase.promise<any> { var useraux2: string; await this.getcurrentuserid(newemail, company).then((useraux) => { useraux2 = useraux; }); console.log('useraux2 ==============>>>> ' + useraux2); //this 1 undefinned await this.updatetoken(useraux2, company).then(() => { return this.afauth.auth.signinwithemailandpassword(newemail, newpassword); }); } // id of single user async getcurrentuserid(email: string, company: string): promise<any>{ var ref = this.db.database.ref(`companies/${company}`); ref.child("users") .orderbychild("semail") .equalto(email) .on("child_added", function(snapshot) { console.log('snapshot.key = ' + snapshot.key); return snapshot.key; }); } async updatetoken(useraux: string, company: string){ var token1: string; token1 = 'hola'; var tokendata = { stoken: token1 }; console.log('useraux = -------------- ' + useraux); var updates = {}; updates['/companies/' + company + '/users/' + useraux] = tokendata; return this.db.database.ref().update(updates); }
Comments
Post a Comment