title: Using Kotlin and Firebase to trigger a sendEmailVerification with onAuthStateChanged callback
body: <p>I'm starting a new Android project and decided to use <strong>Kotlin</strong> and <strong>Firebase</strong> within, right now I'm able to create users successfully using <code>createUserWithEmailAndPassword</code> on my SignupActivity and my users are logged in successfully when createUserWithEmailAndPassword is finished.</p>
  
  <p>Now I'm trying to get it further using the callback event that is triggered on <a href="https://firebase.google.com/docs/reference/android/com/google/firebase/auth/FirebaseAuth.AuthStateListener" rel="nofollow noreferrer">FirebaseAuth.AuthStateListener</a> using <code>onAuthStateChanged(FirebaseAuth auth)</code> but the listener that I'm creating inside my <code>onCreate(savedInstanceState: Bundle?)</code>function isn't get triggered and my lack of experience converting Java code to Kotlin isn't helping me to identify the root problem.</p>
  
  <p>I have some Java example code to base on that goes like this:</p>
  
  <h2>Java example</h2>
  
  <pre><code>onCreate(...//
  mAuthListener = new FirebaseAuth.AuthStateListener() {
      @Override
      public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
          FirebaseUser user = firebaseAuth.getCurrentUser();
          if (user != null) {
              // User is signed in
              // NOTE: this Activity should get onpen only when the user is not signed in, otherwise
              // the user will receive another verification email.
              sendVerificationEmail();
          } else {
              // User is signed out
  
          }
          // ...
      }
  };
  </code></pre>
  
  <h2>My Kotlin code</h2>
  
  <pre><code>    FirebaseAuth.AuthStateListener { auth -&gt;
          val user = auth.currentUser
          if(user != null){
              // User is signed in
              Log.d(TAG, "Signed in")
              Toast.makeText(this, "User", Toast.LENGTH_LONG).show();
              sendVerificationEmail()
          }else{
              // User is signed out
              Log.d(TAG, "Signed out")
              Toast.makeText(this, "Null", Toast.LENGTH_LONG).show();
          }
      }
  </code></pre>
  
  <p>I put some log and toast elements for debugging purpose but neither of them are getting triggered, I'm thinking that the <code>onAuthStateChanged</code> is missing inside the <strong>FirebaseAuth.AuthStateListener</strong> but I don't know how to fix it.</p>
  
  <p>If anyone can give me some advice on what I'm doing wrong it'll be much appreciate.</p>
  
  <p>Thanks in advance.</p>