我使用以下步骤注册新的Firebase用户。我有没有办法设置username
参数,以便将来用户可以使用username
& password
?
另外,有没有办法仅使用username
& password
,即我不想选择电子邮件ID。
我已经完成了以下解决方案,但它看起来并不高效。我想有更好的方法。
Firebase login and signup with username
private FirebaseAuth auth;
//Get Firebase auth instance
auth = FirebaseAuth.getInstance();
//create user
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();
// 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 {
startActivity(new Intent(SignupActivity.this, MainActivity.class));
finish();
}
}
});
答案 0 :(得分:0)
您可以在用户名
后面添加任何域名使用&lt;注册您的用户用户名&gt; @ summersApp.com。
请注意,如果用户忘记密码,将无法重置密码,因为Firebase会使用电子邮件地址发送密码重置电子邮件。
答案 1 :(得分:0)
要在上面的评论中回答OP的问题,
要将更多信息保存给用户,请在数据库中将引用链接到其UID,如图here
示例:
/users
/uid1
no.of.posts: 3,
no.of.friends: 4
/uid2
no.of.posts: 5,
no.of.friends: 6
/uid3
no.of.posts: 7,
no.of.friends: 8