简体   繁体   English

如何在React中存储Firebase用户的uid?

[英]How can I store firebase user's uid in React?

I'm working on a react web application where users can sign up with an email and a password. 我正在开发一个React Web应用程序,用户可以在其中使用电子邮件和密码进行注册。 After signing up, each user will have access to their profile data. 注册后,每个用户都可以访问其个人资料数据。 Below is a my firebase data structure: 以下是我的Firebase数据结构:

users:{
   generatedUserUID:{
            name: "User1"
            profileImage: "http://via.placeholder.com/350x150"
            }
     }

What would be the best way to store the user's uid when the user is signed in so that it can be used throughout the project. 用户登录后存储用户uid的最佳方法是什么,以便可以在整个项目中使用它。 Currently, I'm using the browser's localStorage, but I'm concerned that if the client browser doesn't support localStorage then the app will be rendered useless. 当前,我正在使用浏览器的localStorage,但我担心如果客户端浏览器不支持localStorage,则该应用将变得无用。 So, I'm looking for an alternative and not have to depend on localStorage entirely. 因此,我正在寻找一种替代方法,而不必完全依赖localStorage。 Any help is appreciated. 任何帮助表示赞赏。 Thank you. 谢谢。

You could use a library like Redux to manage data in your application. 您可以使用Redux之类的库来管理应用程序中的数据。 Redux helps you manage the state of your application. Redux帮助您管理应用程序的状态。

More info here : http://redux.js.org/docs/basics/UsageWithReact.html 此处提供更多信息: http : //redux.js.org/docs/basics/UsageWithReact.html

The Firebase SDK can help out here. Firebase SDK可以在这里提供帮助。 The currentUser property, accessed by firebase.auth().currentUser , gives you a User object containing the currently signed in user. firebase.auth().currentUser访问的currentUser属性为您提供一个User对象,其中包含当前登录的用户。

Check out the docs for more info. 查看文档以获取更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 注册帐户后,如何将用户 uid 存储到 firebase 数据库? - How do I store the user uid to firebase database after I register an account? 如何在 firebase 中保存用户的关注者? 反应本机 - How can I save user's followers in firebase? React Native 如何在Algolia的即时搜索中实现使用每个用户的firebase uid进行搜索? - How can searching with each user's firebase uid be implemented in Algolia's instantsearch? 使用 React 和 Firestore 登录后如何通过 UID 获取用户详细信息? - How can I get user details by UID after login with React and Firestore? UID下如何存储Firebase用户 - How To Store Firebase Users Under UID 如何使用 firebase 中的云函数向 uid 发送值? - How can I send a value to uid using cloud functions in firebase? 如何从 firebase 获取用户的 uid? - How can I get the uid of my users from firebase? 使用Firebase,如何创建基于UID的查询? - Using Firebase, how can I create a query based on UID? 如何使用从 firebase 存储的 Auth uid 并更新 Auth 用户信息,例如更改密码、email 和电话号码? - How to use Auth uid that store from firebase and update Auth user information such as change password, email and phone number? 如何使用ionic和firebase获取注册用户的uid - How to get the uid of a registered user with ionic and firebase
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM