最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Adding new data to firebase users - Stack Overflow

programmeradmin2浏览0评论

I want to add a new data to firebase authentication which has data like displayname, phone number, image. But i want to add more such gender, birthday and more. is it possible to add new?

I want to add a new data to firebase authentication which has data like displayname, phone number, image. But i want to add more such gender, birthday and more. is it possible to add new?

Share Improve this question edited Oct 10, 2017 at 3:47 Frank van Puffelen 600k85 gold badges889 silver badges859 bronze badges asked Oct 10, 2017 at 1:44 Wahyu SetiawanWahyu Setiawan 995 silver badges13 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 14

There is no way to add arbitrary additional data to Firebase Authentication user profiles. If you want that, consider using the Firebase Realtime Database (or Cloud Firestore) for storing the additional information.

This approach has been covered in quite a few questions in the past, so I'll link you to those:

  • Firebase: setting additional user properties
  • Add extra User Information with firebase
  • How do I link each user to their data in Firebase?
  • Swift & Firebase - How to store more user data other than email and password?
  • Store additional information during registration with Firebase in Android
  • How to add additional information to firebase.auth()

Since a few weeks ago you can add small bits of information to the Firebase Authentication user profile. While this might sound like what you need, it is explicitly not meant for storing user metadata such as you need. Instead this is intended for storing so-called claims: properties about the user that you then access in the security rules. See the documentation for setting custom claims.

I had the same problem when introducing user roles for authorization in my React with Firebase application. Somehow I wanted to be able to pass a roles property to the authenticated user, but found myself again in Firebase's restrictive framework of doing it their way.

I found a way around it by (1) managing users myself in the Firebase database and (2) merging the authenticated user with the database user when the application loads. Then I am able to add additional user properties (e.g. roles) to my database user, because it will be merged with the authenticated user anyway.

If you are interested in this approach, checkout this tutorial.

发布评论

评论列表(0)

  1. 暂无评论