search

Home  >  Q&A  >  body text

How to use Firebase Authentication with multiple login methods and role-based authentication?

<p>I am creating a react.js application with nodejs as backend and I want to use these authentication methods to log in using email/password, login using google and login using phone, now I want to keep the user while signing Uniqueness For any of these I will also get other details like when user registers using email/password then I will also get user phone number and I don't want user to use that phone number by logging in using phone Create another account method. </p> <p>The second problem is that my application has 3 user roles: User, Sales, and Administrator. There is a different registration form for each user, when a user using email registers as a salesperson, I also want that user to be able to register as a user using the same email, now when I use firebase sdk in my React application, It will throw an error to the user as it already exists. </p> <p>Firebase Authentication can solve this problem, I want the user to be unique, and I want role-based authentication to be enabled. I use firestore as my database</p>
P粉574695215P粉574695215478 days ago670

reply all(1)I'll reply

  • P粉988025835

    P粉9880258352023-09-06 10:29:08

    As doc, "You can allow users to log in to your app using multiple authentication providers by linking the authentication provider credentials to existing user accounts. Regardless of authentication, Users are identified by the same Firebase user ID as the provider they used to log in." See also the linkWithCredential() and linkWithPhoneNumber() methods.

    You can use custom claims based on <的基于角色的访问控制策略/a> (you can add multiple claims, one per role) or Firestore documentation . However, you will implement the mechanism for user selection of roles (you mentioned "different registration forms" in your question) and the corresponding GUI display yourself in your application.

    reply
    0
  • Cancelreply