所有我试图添加一个自定义用户字段来做出反应,我试图使用已注册的用户ID在db中创建单独的用户表。但是,由于某种原因,未定义user.uid时出现错误。谁能告诉我我做错了什么?
import React, { Component } from "react";
import SignUpView from "./SignUpView";
import { withRouter } from "react-router";
import app from "../config/dev";
import { UserRef, timeRef } from '../components/reference';
class SignUpContainer extends Component {
handleSignUp = async event => {
event.preventDefault();
const { email, password,rank } = event.target.elements;
try {
const user = await app
.auth()
.createUserWithEmailAndPassword(email.value, password.value);
console.log(user.email);
UserRef.child(user.uid).set(rank.value);
alert("you have succseffully signed up!!")
this.props.history.push("/");
} catch (error) {
alert(error);
}
};
render() {
return <SignUpView onSubmit={this.handleSignUp} />;
}
}
export default withRouter(SignUpContainer);
答案 0 :(得分:0)
createUserWithEmailAndPassword()
方法返回一个Promise<firebase.auth.UserCredential>
对象。 uid
属性嵌套在firebase.auth.UserCredential.user
属性内。
请尝试以下更新的代码:
try {
const userCredential = await app
.auth()
.createUserWithEmailAndPassword(email.value, password.value);
console.log(userCredential.user.email);
UserRef.child(userCredential.user.uid).set(rank.value);
alert("you have succseffully signed up!!")
this.props.history.push("/");
} catch (error) {
alert(error);
}