Generate parent UID for registration with google a

2020-04-15 20:28发布

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


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 :(


MODEL

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 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();
                        }
                    }
                });

2条回答
劫难
2楼-- · 2020-04-15 21:05

Solution

changed from

FirebaseUtils.getUserRef(account.getEmail())
                                    .setValue(user,

to

 FirebaseDatabase.getInstance().getReference("users")
                                        .child(FirebaseAuth.getInstance().getCurrentUser().getUid())
                                        .setValue(user)
查看更多
淡お忘
3楼-- · 2020-04-15 21:10
                       val ref = database.push().key
                        mapinfoinstance.id = ref!!
                        database.child(ref).setValue(mapinfoinstance)

'mapinfoinstance' is an instance of my class.

I think you want like this: enter image description here

查看更多
登录 后发表回答