生成要向Google Auth Android Studio Firebase注册的父UID [英] Generate parent UID for registration with google auth android studio firebase
问题描述
我需要帮助,如何使用用户模型.创建帐户时,而不是通过电子邮件生成父节点时.将主节点设为uid.我尝试了一些修改,但没有成功,有人可以帮助我.该帐户是由google auth创建的,它希望生成一个主要的uid节点而不是电子邮件.
I need help how can I use user model. when creating the account instead of generating the parent node with email. make the main node the uid. I tried some modifications but I was not successful someone could help me. the account is created by google auth wanted that instead of email it would generate a main uid node.
我搜索了模型,但如果有人可以帮助我,我将不会成功
I searched for models but I was not successful if someone can help me I would be very grateful
我仍然需要电子邮件,但不需要作为主要节点.对于主节点,我需要模型中已经存在的uid,但是我无法进行此更改:(
I still need the email but not as a main node. for the main node I wanted the uid that is already in the model, but I'm not able to make this change :(
模型
public class User implements Serializable {
private String user;
private String email;
private String photoUrl;
private String uid;
private String money;
private String cassinotime;
private String cassinoprofit;
public String getCassinotime() {
return cassinotime;
}
public void setCassinotime(String cassinotime) {
this.cassinotime = cassinotime;
}
public String getCassinoprofit() {
return cassinoprofit;
}
public void setCassinoprofit(String cassinoprofit) {
this.cassinoprofit = cassinoprofit;
}
public User(String user, String email, String photoUrl, String uid, String money) {
this.user = user;
this.email = email;
this.photoUrl = photoUrl;
this.uid = uid;
this.money = money;
}
public User() {
}
public User(String user, String email, String photoUrl, String uid) {
this.user = user;
this.email = email;
this.photoUrl = photoUrl;
this.uid = uid;
}
public String getMoney() {
return money;
}
public void setMoney(String money) {
this.money = money;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhotoUrl() {
return photoUrl;
}
public void setPhotoUrl(String photoUrl) {
this.photoUrl = photoUrl;
}
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
}
Google创建帐户代码
Google create account code
private void firebaseAuthWithGoogle(final GoogleSignInAccount account) {
AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
User user = new User(
);
String photoUrl = null;
if (account.getPhotoUrl() != null) {
user.setPhotoUrl(account.getPhotoUrl().toString());
}
user.setEmail(account.getEmail());
user.setUser(account.getDisplayName());
user.setUid(mAuth.getCurrentUser().getUid());
user.setMoney(money);
user.setCassinotime(cassinotime);
user.setCassinoprofit(cassinoprofit);
FirebaseUtils.getUserRef(account.getEmail())
.setValue(user, new DatabaseReference.CompletionListener() {
@Override
public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
mFirebaseUser = mAuth.getCurrentUser();
finish();
}
});
} else {
dismissProgressDialog();
}
}
});
推荐答案
解决方案
更改自
FirebaseUtils.getUserRef(account.getEmail())
.setValue(user,
到
FirebaseDatabase.getInstance().getReference("users")
.child(FirebaseAuth.getInstance().getCurrentUser().getUid())
.setValue(user)
这篇关于生成要向Google Auth Android Studio Firebase注册的父UID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!