firebase - React-Native firebase 注册我如何获取用户名
问题描述
这是我的注册码;
onButtonClicked1() {
this.setState({
error: '',
loading: true
})
const {username, password} = this.state;
firebase.auth().createUserWithEmailAndPassword(username, password)
.then(this.onRegisterSuccess.bind(this))
.catch(() => {
this.setState({
error : 'Not registered.',
loading: false
})
});
}
我如何获取用户名?获取用户名后,可以在设置页面进行更新。
解决方案
在 promise 解决后,createUserWithEmailAndPassword
firebase 方法将返回一个具有此结构的 Object(将来可能会更改):
{
additionalUserInfo: Object,
credential: null,
operationType: "signIn",
user: {
displayName: string,
email: string,
emailVerified: string,
uid: string,
...
}
}
从那里您可以访问所有可用信息。但是,请记住,这createUserWithEmailAndPassword
是期待email
和password
。因此,如果username
您的应用程序中是电子邮件,那么一切都很好。如果没有,您可能无法获得您想要的结果。
解决 promise 后使用函数的示例:
firebase.auth().createUserWithEmailAndPassword(username, password)
.then((res) => {
callAnyFunctionYouWant(res.user.email) // or res.user.displayName
})
.catch(() => {
...
});
如果您确实想要用户名
如果您有username
要使用的自定义,您需要在之后立即为用户创建一个配置文件,firebase.auth()
并使用不同的查询来获取它。那,你不能用你提供的示例代码来做。它需要额外的工作。
希望这能说明问题。
推荐阅读
- python - 如何在 Python 中禁用 chromedriver“Chrome 正在由自动测试软件控制”通知?
- reactjs - 反应 useEffect 和 setInterval
- reactjs - 使用 docker-compose 的 ASP.NET Core 5.0 React app npm 错误
- security - 我的身份验证流程是否安全/最佳实践?
- python - 从 Jenkins 收集所有日志到 excel 文件
- python - 如何使用线程加速读取 zip 文件
- numpy - Numpy vs Eigen vs Xtensor 线性代数基准奇数
- scala - org.specs2.specification.core.AsExecution[scala.util.Try[org.specs2.matcher.MatchResult[String]]] 类型的证据参数的 specs2 隐式值
- yosys - 如何获取使用门而不是 LUT 的 .bench 文件
- python - venv 从哪里得到点子?