Home > Blockchain >  How to add email&password login method to existing account that was created with a third party provi
How to add email&password login method to existing account that was created with a third party provi

Time:12-25

I just implemented Google OAuth social sign in to my firebase project today, and it works.

  • I have tested it with a new google account (with an email address that wasn't used yet in my firebase project), this worked.

  • I have tested it signing in with my usual google account, which uses the same email address as one of the accounts in my firebase project (with email&password login). In Firebase console I could see the Google logo got added next to the email icon on my user, this is exactly what I expected.


Now my problem is, I don't know how to add email & password login to an existing account, that was created with a third party provider.
To test this I have first created an account on my firebase project using google.

  • I have tried to sign in by using the same email address associated to that google account, which obviously wouldn't work as there is no password set.
  • I have tried to sign up (register) by using the email address, which would throw a FirebaseAuthException with the error code email-already-in-use.
    And I have recognized a flaw in this logic^^: Let's say Bob creates an account on my firebase app with Google. Then just about anybody could use his email address and a new password to register, and therefore login to his account. A correct solution is to only allow the user to add a password while signed in or by requiring authentication.
  • I couldn't find any relevant method on FirebaseAuth.instance that could be the answer to my question.

I have noticed that many apps with social logins provide the Apple login ONLY for their iOS app.
If I do the same, the worst case scenario I can think of which is caused by this problem is:

  1. Someone with an iPhone downloads my app and creates an account with Apple login.
  2. Then that person switches to Android. Now that person can't use Apple login, and also can't log in to my app with their email address.

So for now, I have to include Apple login for my Android app too, and I don't see a reason why I should not do that. But I still want to find a solution to my question, as that could be an annoyance to users of my app.

See this video from the official Firebase YouTube account.


I want to clarify, my questions is different from this, so don't redirect me to it.

CodePudding user response:

I have just found the answer to my question and implemented the funcitonality in my own project.

This webpage from the official firebase docs explains exactly how to do that.

  • Related