Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用户名唯一并将其保存在Firebase数据库中_Android_Firebase_Firebase Authentication - Fatal编程技术网

Android 使用户名唯一并将其保存在Firebase数据库中

Android 使用户名唯一并将其保存在Firebase数据库中,android,firebase,firebase-authentication,Android,Firebase,Firebase Authentication,我正在开发一个android appAndroid Studio,它要求用户注册/登录才能访问它。我正在使用firebase存储注册用户。目前,注册表单采用用户的电子邮件、密码和姓名,登录只需要电子邮件和密码。以下是我的注册活动: private void createUserAccount(final String email, final String name, String password) { mAuth.createUserWithEmailAndPassword

我正在开发一个android appAndroid Studio,它要求用户注册/登录才能访问它。我正在使用firebase存储注册用户。目前,注册表单采用用户的电子邮件、密码和姓名,登录只需要电子邮件和密码。以下是我的注册活动:

 private void createUserAccount(final String email, final String name, String password) {
        mAuth.createUserWithEmailAndPassword(email,password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {

            @Override
            public void onComplete(@NonNull Task<AuthResult> task) {
               if(task.isSuccessful()){
                   showMessage("Account Created");
                   updateUserInfo(name, pickedImgUri,mAuth.getCurrentUser());
               }
               else{
                   showMessage("account_activity creation failed" + task.getException().getMessage());
                   regBtn.setVisibility(View.VISIBLE);
                   loadingProgress.setVisibility(View.INVISIBLE);
               }
            }
        });

    }
           private void updateUserInfo(final String name, Uri pickedImgUri, final FirebaseUser currentUser) {
            StorageReference mStorage = FirebaseStorage.getInstance().getReference().child("user_photos");
            final StorageReference imageFilePath = mStorage.child(pickedImgUri.getLastPathSegment());
            imageFilePath.putFile(pickedImgUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                @Override
                public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                    imageFilePath.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
                        @Override
                        public void onSuccess(Uri uri) {
                            UserProfileChangeRequest profileUpdate = new UserProfileChangeRequest.Builder()
                                    .setDisplayName(name)
                                    .setPhotoUri(uri)
                                    .build();

                            currentUser.updateProfile(profileUpdate)
                                    .addOnCompleteListener(new OnCompleteListener<Void>() {
                                        @Override
                                        public void onComplete(@NonNull Task<Void> task) {
                                            if (task.isSuccessful()){
                                                showMessage("Register complete");
                                                UpdateUI();
                                            }
                                        }
                                    });
                        }
                    });
                }
            });

    }

如何添加用户名字段并使其对每个用户都是唯一的?是否有可能使所有用户信息都显示在Firebase数据库上而不是在身份验证下

除了已有的配置文件字段外,无法在身份验证用户上创建配置文件字段

对于用户名,最好在firestore中创建用户集合。每个条目都可以由用户从auth分配的UID设置密钥。创建条目时,请使用用户名字段进行创建。然后,在任何新用户锁定其用户名之前,您可以使用where'username'、'=='、$username对firestore运行查询,其中$username是用户试图保留的名称。如果记录存在,则使用用户名,用户必须选择其他内容

下面是一个YouTube教程,介绍如何将auth和firestore一起用于像您这样的用例: