Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firebase Auth UI not showing sign in flow when offline #1585

Closed
kaushalyap opened this issue Feb 21, 2019 · 9 comments
Closed

Firebase Auth UI not showing sign in flow when offline #1585

kaushalyap opened this issue Feb 21, 2019 · 9 comments

Comments

@kaushalyap
Copy link

kaushalyap commented Feb 21, 2019

First I asked a question on SO but there was no solution. This may be a bug or my mistake.

Step 2: Describe your environment

  • Android device: LG Zero
  • Android OS version: 6.0
  • Google Play Services version: play-services-auth : 16.0.1
  • Firebase/Play Services SDK version: , firebase-core:16.0.6
  • FirebaseUI version: 4.3.1

Step 3: Describe the problem:

When running the app firebase auth ui sign in flow is not show, instead shows the main activity, which in this case a blank constraint layout.

Steps to reproduce:

  1. Clone the repository at https://github.com/nerdyadventurer/firebase-auth-ui
  2. open project using android studio and setup firebase authentication(enable Google and Email authentication providers from the firebase console)
  3. Run the app

Observed Results:

  • What happened? This could be a description, logcat output, etc.
    Logcat is empty.
    Shows the main activity (which is black in this case)

Expected Results:

  • What did you expect to happen?
    Showing the sign in flow with Google sign in, email sign in buttons and etc.

Relevant Code:

dependencies

dependencies {
  implementation fileTree(dir: 'libs', include: ['*.jar'])
  implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
  implementation 'androidx.appcompat:appcompat:1.1.0-alpha02'

  implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

  // firebase
  implementation 'com.firebaseui:firebase-ui-auth:4.3.1'
  implementation 'com.google.firebase:firebase-core:16.0.6'
  implementation 'com.google.firebase:firebase-auth:16.1.0'
  implementation 'com.google.android.gms:play-services-auth:16.0.1'

  // testing
  testImplementation 'junit:junit:4.12'
  androidTestImplementation 'androidx.test:runner:1.1.2-alpha01'
  androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.2-alpha01'
}

MainActivity.kt

package example.com.firebaseauthui

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.firebase.ui.auth.AuthUI
import com.firebase.ui.auth.IdpResponse
import com.google.firebase.auth.FirebaseAuth


class MainActivity : AppCompatActivity() {

    private lateinit var mFirebaseAuth: FirebaseAuth
    private  lateinit var mAuthStateListener: FirebaseAuth.AuthStateListener


    override fun onCreate(savedInstanceState: Bundle?) {

        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        // Initialize Firebase Auth
        mFirebaseAuth = FirebaseAuth.getInstance()



        mAuthStateListener = FirebaseAuth.AuthStateListener { firebaseAuth ->

            val user = mFirebaseAuth.currentUser


            if (user != null){
                Toast.makeText(applicationContext, "Already signed in", Toast.LENGTH_LONG).show()
            }
            else{
                // Choose authentication providers
                val providers = arrayListOf(
                    AuthUI.IdpConfig.EmailBuilder().build(),
                    AuthUI.IdpConfig.GoogleBuilder().build())

                // Create and launch sign-in intent
                startActivityForResult(
                    AuthUI.getInstance()
                        .createSignInIntentBuilder()
                        .setIsSmartLockEnabled(false)
                        .setAvailableProviders(providers)
                        //.setLogo(R.drawable.my_great_logo)      // Set logo drawable
                        .setTheme(R.style.AppTheme)      // Set theme
                        .setAvailableProviders(providers)
                        .setTosAndPrivacyPolicyUrls(
                            "https://example.com/terms.html",
                            "https://example.com/privacy.html")

                        .build(),
                    RC_SIGN_IN)
            }
        }

    }

    public override fun onStart() {
        super.onStart()
        mFirebaseAuth.addAuthStateListener ( mAuthStateListener )
    }



//    override fun onResume() {
//        super.onResume()
//        mFirebaseAuth.addAuthStateListener { mAuthStateListener }
//
//    }

    override fun onPause() {
        super.onPause()
        mFirebaseAuth.removeAuthStateListener ( mAuthStateListener )
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)

        if (requestCode == RC_SIGN_IN) {
            val response = IdpResponse.fromResultIntent(data)

            if (resultCode == Activity.RESULT_OK) {
                // Successfully signed in
                val user = FirebaseAuth.getInstance().currentUser

                // ...
            } else {
                // Sign in failed. If response is null the user canceled the
                // sign-in flow using the back button. Otherwise check
                // response.getError().getErrorCode() and handle the error.
                // ...
            }
        }
    }

    private fun signOut() {

        AuthUI.getInstance()
            .signOut(this)
            .addOnCompleteListener {
                // ...
            }
    }

    companion object {

        private const val RC_SIGN_IN = 123
    }

}

Please help

@samtstern
Copy link
Contributor

@NerdyAdventurer there are a few things that stand out to me here:

  • Can you try removing implementation 'androidx.appcompat:appcompat:1.1.0-alpha02' and replacing it with a non-alpha version? Preferably a stable version.
  • Can you try removing the line .setTheme(R.style.AppTheme) to see if it makes a difference?

@kaushalyap
Copy link
Author

Actually I tried the changes you suggested but this time with my Wifi turned on, it did shows login buttons. so I revert the changes it worked when wifi turned on, but not when the wifi turned off.

May I ask why it necessary to have internet connection just to show couple of sign in buttons? are not they just couple of buttons on an activity/fragment?

@samtstern
Copy link
Contributor

samtstern commented Feb 22, 2019 via email

@kaushalyap
Copy link
Author

I was also surprised why does it work with Wifi. Before all this I tried to use the app in the repo just downloading the app folder, it needs lot of work to get it to work since its not a complete project. Can please give me steps to get it to work?

@kaushalyap kaushalyap reopened this Feb 22, 2019
@kaushalyap
Copy link
Author

@samtstern I was considering to use authUI for production, with this experience, restrictions of authUI and bugs on this repo it seems to me that this is not suitable for production app.

@kaushalyap kaushalyap changed the title Firebase Auth UI shows a blank screen Firebase Auth UI not showing sign in flow Feb 22, 2019
@samtstern
Copy link
Contributor

@NerdyAdventurer to run the sample app:

  1. Clone this whole repo
  2. Get a google-services.json file for com.firebase.uidemo and place it in the app directory
  3. Run ./gradlew :app:installDebug to install the app on your device or emulator (or run app in Android Studio)

That said I realize that you are right (I was mistaken about the flow). We cancel the sign-in flow if there is no internet available. It happens here in KickoffActivity:

        GoogleApiAvailability.getInstance()
                .makeGooglePlayServicesAvailable(this)
                .addOnSuccessListener(this, new OnSuccessListener<Void>() {
                    @Override
                    public void onSuccess(Void aVoid) {
                        if (savedInstanceState != null) {
                            return;
                        }

                        if (isOffline()) {
                            finish(RESULT_CANCELED, IdpResponse.getErrorIntent(
                                    new FirebaseUiException(ErrorCodes.NO_NETWORK)));
                        } else {
                            mKickstarter.start();
                        }
                    }
                })
                .addOnFailureListener(this, new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {
                        finish(RESULT_CANCELED, IdpResponse.getErrorIntent(new FirebaseUiException(
                                ErrorCodes.PLAY_SERVICES_UPDATE_CANCELLED, e)));
                    }
                });

I think this is the right behavior if SmartLock is enabled, however in the case where SmartLock is disabled we should probably allow you to show the sign-in buttons and then fail only on action.

@samtstern samtstern changed the title Firebase Auth UI not showing sign in flow Firebase Auth UI not showing sign in flow when offline Feb 22, 2019
@samtstern samtstern added this to the 4.3.2 milestone Feb 22, 2019
@samtstern
Copy link
Contributor

@NerdyAdventurer see #1586

@kaushalyap
Copy link
Author

kaushalyap commented Feb 24, 2019

@samtstern side question, does the firebase auth ui comes with a forgot password screen, I cannot see any links to such thing? no docs either.

@samtstern
Copy link
Contributor

This has been fixed and released in version 4.3.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants