java Firebase电子邮件注册,登录和注销
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java Firebase电子邮件注册,登录和注销相关的知识,希望对你有一定的参考价值。
private FirebaseAuth mAuth;
mAuth = FirebaseAuth.getInstance();
@Override
public void onStart() {
super.onStart();
FirebaseUser currentUser = mAuth.getCurrentUser();
if (currentUser != null) {
Intent myIntent = new Intent(MainActivity.this, Main3Activity.class);
startActivity(myIntent);
finish();
}
}
mAuth.createUserWithEmailAndPassword(email.getText().toString(), password.getText().toString())
.addOnCompleteListener(Main2Activity.this, new OnCompleteListener < AuthResult > () {
@Override
public void onComplete(@NonNull Task < AuthResult > task) {
if (task.isSuccessful()) {
FirebaseUser user = mAuth.getCurrentUser();
UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
.setDisplayName(fname.getText().toString() + " " + lname.getText().toString())
.build();
user.updateProfile(profileUpdates);
Toast.makeText(Main2Activity.this, "User has been created", Toast.LENGTH_SHORT).show();
mAuth.signInWithEmailAndPassword(email.getText().toString(), password.getText().toString())
.addOnCompleteListener(Main2Activity.this, new OnCompleteListener < AuthResult > () {
@Override
public void onComplete(@NonNull Task < AuthResult > task) {
if (task.isSuccessful()) {
Intent myIntent = new Intent(Main2Activity.this, Main3Activity.class);
startActivity(myIntent);
finish();
} else {
Toast.makeText(Main2Activity.this, "Authentication failed.", Toast.LENGTH_SHORT).show();
}
}
});
} else {
Log.w("demo", "createUserWithEmail:failure", task.getException());
Toast.makeText(Main2Activity.this, "Authentication failed", Toast.LENGTH_SHORT).show();
}
}
});
//Logout
FirebaseAuth.getInstance().signOut();
以上是关于java Firebase电子邮件注册,登录和注销的主要内容,如果未能解决你的问题,请参考以下文章
错误:Firebase Auth Google 删除 EmailPassword Auth
Firebase:注销后登录卡在加载中
如何使用 Flutter 在 Firebase 中正确登录和注册?
将电子邮件更新到 firebase
Firebase 电子邮件验证行为
在确认注册之前验证用户的电子邮件地址,使用 Flutter 和 Firebase