Situation:
I am working on an e-commerce project where a user has the option to do shopping and/or can do business as well.
Feature:
To do shopping or to do business user has to create an account and for this purpose, I am using Firebase authentication to store User Credentials like Username
and Password
.
Problem:
User trying to create an account for shopping with username (ex: [email protected])
, but If the same user wants to do business with the same account then the user is unable to create the business account with the same username
.
Question:
So is there any way to store the same username/email with a different uid in Firebase authentication?
if the answer is no!
What will be another optimal solution to this problem?
Note:
I have enabled to create multiple accounts for each identity provider but the error still exists.
ERROR:
The email address is already in use by another account.
2
Answers
Rather than creating a separate UID for the same email, you should maintain a table / record / collection containing access level or type of user (e.g,
isBusiness
/isCustomer
) for each user.No, you cannot have two different users with the same email address
If you enable that, it doesn’t mean that you’ll have different users, you’ll just link an auth provider credentials to an existing user account.
The simplest solution I can think of would be to add in the authentication screen an option to select what the user wants to do shopping or business. According to the selection, you can redirect the user to a specific screen. Please note that it’s an "or" operation. You cannot do both at the same time.
If you need to differentiate the type operation in the database, then then Firestore schema might look like this: