我正在调用uid进行存储,并且它不断得到未定义的错误?
handleAdminSubmit(e) {
e.preventDefault()
const auth = firebase.auth();
let promise = auth.createUserWithEmailAndPassword(this.state.SubEmail, this.state.subPasswrd);
promise.then(user=> {
console.log(user.uid)
let email = this.state.SubEmail
let em = email.replace('.com', '')
let db = firebase.database();
db.ref("Admins").child(em)
.set({ "Admin": this.state.SubEmail, "password": this.state.subPasswrd, "Name": this.state.adminName })
.then(e => {
console.log("succes")
this.FetchAdmins()
});
})
promise.catch(e => {
alert("admin not created , Try again")
})
}
答案 0 :(得分:0)
uid
对象上有auth
:
const auth = firebase.auth();
let promise = auth.createUserWithEmailAndPassword(this.state.SubEmail, this.state.subPasswrd);
promise.then(() => {
console.log(auth.uid)
...
答案 1 :(得分:0)
您传递给then
的类型是UserCredential
。要获得实际用户,您必须访问该用户的user
属性。所以:
auth.createUserWithEmailAndPassword(this.state.SubEmail, this.state.subPasswrd);
.then(credential => {
console.log(credential.user.uid)