Skip to content

Instantly share code, notes, and snippets.

@boomboompower
Forked from ahtaufiiq/Create Account dan Sign In
Last active April 5, 2018 22:57
Show Gist options
  • Save boomboompower/edf101c2cc877112892eb57461835311 to your computer and use it in GitHub Desktop.
Save boomboompower/edf101c2cc877112892eb57461835311 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(LoginActivity.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(LoginActivity.this, MainActivity.class);
startActivity(i);
} else {
Toast.makeText(LoginActivity.this, "Authentication Failed",
Toast.LENGTH_SHORT).show();
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment