Hary
Hary

Reputation: 5818

How to send Verification Email after signup

I am using Firebase for user signup but I could not find any method to send verification email after signup.

auth = FirebaseAuth.getInstance();

auth.createUserWithEmailAndPassword(email, password)
    .addOnCompleteListener(SignupActivity.this, new OnCompleteListener<AuthResult>() {
        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {
            Toast.makeText(SignupActivity.this, "createUserWithEmail:onComplete:" + task.isSuccessful(), Toast.LENGTH_SHORT).show();
            progressBar.setVisibility(View.GONE);
            // If sign in fails, display a message to the user. If sign in succeeds
            // the auth state listener will be notified and logic to handle the
            // signed in user can be handled in the listener.
            if (!task.isSuccessful()) {
                Toast.makeText(SignupActivity.this, "Authentication failed." + task.getException(),
                        Toast.LENGTH_SHORT).show();
            } else {
                FirebaseUser user = auth.getCurrentUser()

                startActivity(new Intent(SignupActivity.this, MainActivity.class));
                finish();
            }
        }
    });

Upvotes: 0

Views: 68

Answers (1)

Peter Haddad
Peter Haddad

Reputation: 80914

You can send an address verification email to a user with the sendEmailVerification method. For example:

FirebaseAuth auth = FirebaseAuth.getInstance();
FirebaseUser user = auth.getCurrentUser();

user.sendEmailVerification()
    .addOnCompleteListener(new OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {
            if (task.isSuccessful()) {
                Log.d(TAG, "Email sent.");
            }
        }
    });

more info here: https://firebase.google.com/docs/auth/android/manage-users

Upvotes: 1

Related Questions