10

I knew that we can verify the users email with Firebase Auth 3.0. I'm not able to find any documentation regarding email verification on Android. I'm able to find the same for iOS as well as web but not for Android. Any link to the documentation would be helpful.

Email Types

From the image, it is clear that once the user signs in, he will be intimated regarding that on email to confirm his subscription. I've subscribed myself and also verified in the users section in Auth tab and I am able to see my mail id and firebase generated unique user id. What's missing here is the confirmation email to my email id. Did some one try this or am I too early trying this? Thanks for your help.

Vijay
  • 838
  • 9
  • 30
  • To verify the behavior, i even tried with two other mail id's and am not able to get any verification email. – Vijay May 24 '16 at 17:36
  • The state of your question has changed; there's a more up-to-date answer now available. – Makoto Nov 03 '16 at 15:38

4 Answers4

13

Email verification for android is now available in Firebase. See this release note: https://firebase.google.com/support/release-notes/android#9.6

Rahul
  • 203
  • 2
  • 9
11

Update

Email verification is available in version 9.6 and higher of the Firebase SDK for Android.

Original answer

Email verification is not available for Android yet. Also answered here with more context.

Frank van Puffelen
  • 418,229
  • 62
  • 649
  • 645
Kato
  • 38,684
  • 6
  • 110
  • 135
  • @FrankvanPuffelen: this answer [is being discussed on Meta](http://meta.stackoverflow.com/q/337366/1079354). – Makoto Nov 03 '16 at 15:39
3

An alternative suggested by the Firebase team

One thing you could do is to add a node to your Firebase Database which contains all email addresses as children. You should make this node only publicly readable (via Firebase security rules).

Then from within your apps, once a user signs up / signs in, you check if the email of that user is on the list, and if not, you sign them out and kick them out of your app (and as a bonus, you could even log the intruder's email address in your database, so you can later check who is trying to access your app).

This will work for initial testing if you know the e-mail ids of the people who are gonna test your app until the e-mail verification makes its way to Android.

Vijay
  • 838
  • 9
  • 30
3

Since email verification only works with Email/Password authentication, the best place to send it wold be in the onComplete method of createUserWithEmailAndPassword(...) method, after signup is successful.

firebaseAuth.createUserWithEmailAndPassword(email, password)
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        if (task.isSuccessful()) {
                            sendVerificationEmail();
                         ....

The custom sendVerification method is:

public void sendVerificationEmail() {
    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

    if (user != null) {
        user.sendEmailVerification()
                .addOnCompleteListener(new OnCompleteListener<Void>() {
                    @Override
                    public void onComplete(@NonNull Task<Void> task) {
                        if (task.isSuccessful()) {
                            Toast.makeText(SignUpActivity.this, "Signup successful. 
                                Verification email sent", Toast.LENGTH_SHORT).show();
                        }
                    }
                });
    }

}

You can then check if the user has verified their email anywhere in your app by calling:

mAuthListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
          firebaseUser = firebaseAuth.getCurrentUser();
            if (firebaseUser != null ) {
                Log.e(TAG, firebaseUser.isEmailVerified() ? "User is signed in and email is verified" : "Email is not verified");
            } else {
                Log.e(TAG, "onAuthStateChanged:signed_out");
            }
        }
    };
Ojonugwa Jude Ochalifu
  • 23,935
  • 25
  • 104
  • 122