0

I am new to firebase and I have followed the basic tutorials to implement an app with username/password authentication as well as Google authentication.

This obviously allows me to log on to an application but I want to register a user and assign them a specific role. As an example I might have two types of users in an application, a buyer and a seller or someone requesting a service and a service provider. I have a basic registration page for email/password users which I could potentially add in an extra field to indicate what type of user they are but I am not sure how to implement a registration page for federated identity providers such as google and twitter.

How do I register a user with specific roles using one of these providers?

I have searched for examples but I haven't been able to find what I am after.

pjr
  • 9
  • 1
  • See most of the top answers here: https://www.google.com/search?q=site:stackoverflow.com+firebase+add+user+properties – Frank van Puffelen Apr 15 '17 at 08:14
  • Thanks @FrankvanPuffelen. I must be missing something obvious but I still don't understand how this works with an identity provider like Google, Twitter or Facebook – pjr Apr 15 '17 at 08:44
  • You cannot add properties to existing identity providers. So you will either have to create your own identity provider or store the properties elsewhere, where the system you're trying to secure can access them. – Frank van Puffelen Apr 15 '17 at 09:15
  • OK @FrankvanPuffelen. I understand I can't add properties to existing identity providers and at the moment I have no interest in creating my own identity provider. I understand that I need to have to create a new property store for user details but I'm not sure how to associate these user details with the 3rd party identity provider. How do I register a user who wants to authenticate with google but store additional details about that user in firebase. Sorry if this is a stupid question but I can't seem to make that link. – pjr Apr 15 '17 at 09:31
  • That's why I also provided a search. Questions like [this](http://stackoverflow.com/q/19520615), [this](http://stackoverflow.com/q/31038611), [this](http://stackoverflow.com/q/37926672) and [this](http://stackoverflow.com/questions/14673708) all deal with the same topic. If you can't make any of it work, post the [minimal code that reproduces where you're stuck](http://stackoverflow.com/help/mcve). – Frank van Puffelen Apr 15 '17 at 09:46
  • Thanks @FrankvanPuffelen. Reading those pages definitely made it clearer on how to add additional user details. and I will certainly be going down that path. I still don't think it answers my original query which may have been unclear about registering a user who uses google authentication (or Twitter etc). I will keep search for a clear example of how to do that and post back when I have found it. – pjr Apr 17 '17 at 08:59

1 Answers1

1

Unfortunately, you can't add extra fields to FirebaseUser. You have to use "real-time database". You can create a database node called "users" and save there your user-specific fields (use FirebaseUser UID as the key for the database). Then when the user login in your app you can get their info from the database.

To explain in details: you have to use firebase authentication to login and register users, after that (for example on register completion) you save user's information in the real-time database node. Then after login (with firebase authentication) you will use user's uid to get all the user's details from the real-time database. You need this also if your users can view other user's profile... you can't get another user information from the "authentication table".

Utnapishtim
  • 256
  • 1
  • 2
  • 12
  • Thanks @Utnapishtim I will look into the separate Users table but how do I register a user who will authenticate themselves via Google, Facebook, Twitter with this table? I can't seem to find an example of this. – pjr Apr 15 '17 at 08:48
  • No, you have to use firebase authentication to register and login users. You have to use the real-time database to store other information that firebase doesn't save in the "authentication". I will edit the answer. – Utnapishtim Apr 15 '17 at 21:06