Home > database >  Unable to find the password parameter that is passed to EmailAuthProvider
Unable to find the password parameter that is passed to EmailAuthProvider

Time:03-09

I am currently trying to convert an anonymous account into a permanent one using Android Firebase. I am using the email-password provider as a method to create an account. The docs state that you must pass a password parameter into the following code :

val credential = EmailAuthProvider.getCredential(email, password)

My code is the following, I use the FirebaseAuth instance to access the current user which then allows me to access their email however I cannot find a way to access the password:

val credential = EmailAuthProvider.getCredential(mAuth.currentUser.email, password)

Other links I have taken a look at do not improve clarity and cause further confusion.

Firebase Authentication : how to get current user's Password? How to create "credential" object needed by Firebase web user.reauthenticateWithCredential() method? Firebase get current user password

Additionally, the last link states that for security reasons we cannot get the password.

CodePudding user response:

I am currently trying to convert an anonymous account into a permanent one using Android Firebase. I am using the email-password provider as a method to create an account.

From this sentence, I understand that you already have anonymous accounts in your project and you try to convert them into permanent users using user and password.

The docs state that you must pass a password parameter into the following code:

val credential = EmailAuthProvider.getCredential(email, password)

That is a normal requirement. Since your anonymous users can join your app without any credentials, in order to be able to convert them, you need to ask each user for an email and a password. That can be simply done in Android, using two EditText objects.

Once you got the user input, you can call getCredential() and pass those values as arguments. Once did that, you can call:

auth.currentUser!!.linkWithCredential(credential)
                            .addOnCompleteListener(this) { /* ... */ }

Please note that auth.currentUser represents the anonymous users. When you call linkWithCredential() and you pass the credential object as an argument, you're actually converting the anonymous user into a permanent user.

CodePudding user response:

Since the current account is anonymous, it doesn't have an email and password yet.

The common flow is that you first sign in the user anonymously, without asking them for any information. Then later (when the user is ready to sign in explicitly) you ask them for their email and password, use those to create email credentials, and then link them to the anonymous account.

  • Related