firebase / FirebaseUI-Android

Optimized UI components for Firebase
https://firebaseopensource.com/projects/firebase/firebaseui-android/
Apache License 2.0
4.63k stars 1.83k forks source link

onActivityResult not called when using "sign in with email" #2169

Open DaveInAus opened 2 weeks ago

DaveInAus commented 2 weeks ago

Step 3: Describe the problem:

onActivityResult not called when using "sign in with email" i.e. when using an email link to sign-in. The application is supposed to save the users email during this flow and it would seem a result should be returned to the activity so it can be handled.

Steps to reproduce:

  1. Start a Firebase UI Activity startForResult.launch(Intent(context, FirebaseUIActivity::class.java))
  2. Add an Email Provide AuthUI.IdpConfig.EmailBuilder() .enableEmailLinkSignIn() .setActionCodeSettings(actionCodeSettings) .build(),
  3. When the user has gone through the flow to save the users email so that it can be used when the user clicks on the link the onActivityResult is not called so that the users email can be saved somewhere

Observed Results:

onActivityResult no called

Expected Results:

Relevant Code:

ublic class FirebaseUIActivity : AppCompatActivity() {

    // [START auth_fui_create_launcher]
    // See: https://developer.android.com/training/basics/intents/result
    private val signInLauncher = registerForActivityResult(
        FirebaseAuthUIActivityResultContract()
    ) { res ->
        var idToken : String? = null
        this.onSignInResult(res)
     }}

   override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
          super.onActivityResult(requestCode, resultCode, data)
  }
DaveInAus commented 2 weeks ago

Potentially this can really only be solved by updating the FirebaseUI Library

In auth/src/main/java/com/firebase/ui/auth/ui/email/EmailLinkFragment.java (https://github.com/firebase/FirebaseUI-Android)

it would be good to add a line to save the email to SharePreferences in

@Override
            protected void onSuccess(@NonNull String email) {
                Log.w(TAG, "Email for email link sign in sent successfully.");

                //*.   SAVE email TO SHARED PREFERENCES  *//

                doAfterTimeout(() -> mTopLevelView.setVisibility(View.VISIBLE));       
                mEmailSent = true;
            }

or alternatively if someone knows how to intercept this email during the passwordless email link flow it would be great to provide an example