我想要获取新创建的用户的用户id,这样我就可以将文档命名为该uid,但显示为null。
这是我的代码
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
})
},另外,我这样做对吗?因为我是以管理员身份登录的?我想在不注销的情况下创建一个新用户。
发布于 2019-11-06 20:51:09
我不能完全确定,但我认为问题出在使用createUserWithEmailAndPassword返回的promise时。
据我所知,应该是这样的:
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://stackoverflow.com/questions/58730470
复制相似问题