Skip to content

Instantly share code, notes, and snippets.

@ahtaufiiq
Last active April 5, 2018 23:11
Show Gist options
  • Save ahtaufiiq/1b2182845facc89e56148371e9387a23 to your computer and use it in GitHub Desktop.
Save ahtaufiiq/1b2182845facc89e56148371e9387a23 to your computer and use it in GitHub Desktop.
Create Account and SignIn using Firebase Authentication
private void createAccount(final String email, final String password) {
mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Intent i = new Intent(LandingActivity.this, MainActivity.class);
startActivity(i);
} else {
Toast.makeText(LoginActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
}
}
});
}
private void signIn(String email, String password) {
mAuth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Intent i = new Intent(LandingActivity.this, MainActivity.class);
startActivity(i);
} else {
Toast.makeText(LoginActivity.this, "Akun Belum Terdaftar",
Toast.LENGTH_SHORT).show();
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment