Firebase Auth returns wrong value

import android.support.annotation.NonNull;
import android.util.Log;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseAuthInvalidCredentialsException;
import com.google.firebase.auth.FirebaseAuthInvalidUserException;
import com.google.firebase.auth.FirebaseAuthUserCollisionException;
import com.google.firebase.auth.FirebaseUser;
import com.sachintitus.instafy.instafy.repository.Model.Status;


public class FirebaseAuthentication implements Authentication {

    public static String TAG = "FIREBASEAUTHENTICATION";

    public Status userAuthStatus;
    private FirebaseAuth mAuth;

    public FirebaseAuthentication() {
        mAuth = FirebaseAuth.getInstance();
        userAuthStatus = Status.SIGNED_OUT;
    }

    @Override
    public Status signIn(String email, String password) {
        Log.w("AUTH", "Started");
        mAuth.signInWithEmailAndPassword(email, password)
            .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {
                        // Sign in success, update UI with the signed-in user's information
                        FirebaseUser user = mAuth.getCurrentUser();

                        userAuthStatus = Status.SIGNIN_SUCCESS;
                        Log.w(TAG, "signInWithEmail:success");
                        Log.w(TAG, String.valueOf(userAuthStatus));

                    } else {
                        // If sign in fails, display a message to the user.
                        Log.w(TAG, "signInWithEmail:failure", task.getException());

                        if (task.getException() instanceof FirebaseAuthInvalidUserException) {
                            Log.w(TAG, "signInWithEmail: failure", task.getException());
                            userAuthStatus = Status.SIGNIN_FAILED_NEW_USER;
                        }
                        if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
                            Log.w(TAG, "SignInWithEmail: Faulure", task.getException());
                            userAuthStatus = Status.SIGNIN_FAILED_WRONG_PASSWORD;
                        }

                    }

                    // ...
                }
            });
        Log.w(TAG, "returns" + userAuthStatus);
        return userAuthStatus;
    }

    @Override
    public void signUp(String email, String password) {

        mAuth.createUserWithEmailAndPassword(email, password)
            .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {
                        // Sign in success, update UI with the signed-in user's information
                        Log.d(TAG, "createUserWithEmail:success");
                        FirebaseUser user = mAuth.getCurrentUser();
                        userAuthStatus = Status.SIGNUP_SUCCESS;

                    } else {
                        // If sign up fails, display a message to the user.
                        Log.w(TAG, "createUserWithEmail:failure", task.getException());

                        if (task.getException() instanceof FirebaseAuthUserCollisionException) {
                            Log.w(TAG, "User already exists, sign up failed", task.getException());
                            userAuthStatus = Status.SIGNUP_FAILED_EXISTING_USER;

                        }
                    }
                }
            });

    }
}
This piece of code returns Enum values as the user is signed in. When the app started, the status should be SIGNED_OUT, and it should change to SIGNIN_SUCCESS as FirebaseAuth sign in is successful. However it always returns SIGNED_OUT.
More details:
Value of local status object changes inside the onComplete and onFail functions
This value is returned when authentication is completed
Thanks in advance

Комментарии

Популярные сообщения из этого блога

Как преобразовать вертикальную запись в горизонтальную?

Skipping acquire of configured file 'contrib/binary-i386/Packages' as repository … doesn't support architecture 'i386'

How to delete a folder in remote Windows from Linux