需要有关JavaScript中的Firestore的帮助

我想获取新创建的用户的用户ID,以便可以将我的文档命名为该uid,但它表示为空。

这是我的代码

addDriver(){
    var $this = this
    secondaryApp.auth().createUserWithEmailAndPassword($this.driver.email,$this.driver.password).then(function(user){
        $this.$db.collection("driver").doc(user.uid)
            .set({
                fname: $this.driver.fname,lname: $this.driver.lname,contact_number: $this.driver.cnum,license_number: $this.driver.license,email: $this.driver.email,password: $this.driver.password,})
            secondaryApp.auth().signOut();
        $this.formHeaderStatus = $this.$db.auth().currentUser
    })
},

我也正确吗?我以管理员身份登录?而且我想创建一个新用户而不注销自己。

soon11 回答:需要有关JavaScript中的Firestore的帮助

我不确定,但是我相信问题在于使用createUserWithEmailAndPassword返回的诺言。

从我收集到的信息来看,应该像这样:

addDriver(){
    var $this = this
    secondaryApp.auth().createUserWithEmailAndPassword($this.driver.email,$this.driver.password).then(function(**data**){
        $this.$db.collection("driver").doc(**data.user.uid**)
            .set({
                fname: $this.driver.fname,lname: $this.driver.lname,contact_number: $this.driver.cnum,license_number: $this.driver.license,email: $this.driver.email,password: $this.driver.password,})
            secondaryApp.auth().signOut();
        $this.formHeaderStatus = $this.$db.auth().currentUser
    })
},

希望对您有所帮助,否则请告诉我。

但是正如Franck所说,如果要在保持登录状态下注册新用户,则应在后端或Cloud Functions中使用Admin-SDK

本文链接:https://www.f2er.com/3152129.html

大家都在问