简体   繁体   English

在 Firestore 中,如何获取 Firebase Authentication 的 uid 为文档?

[英]In Firestore, how to get the uid of Firebase Authentication to be a document?

How can I get the firebase current uid of firebase Authentication to be a document?如何将 firebase Authentication 的 firebase 当前 uid 作为文档? I am a beginner.我是初学者。

This is my Java file that I want to get the id这是我想要获取 id 的 Java 文件

public class Question extends AppCompatActivity {

    private FirebaseFirestore db = getInstance();
    FirebaseUser user;
    private EditText e1,e2,e3;
    FirebaseAuth mAuth;
    private Button b1;

    ProgressDialog progressDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_question);

        e1 = findViewById(R.id.editText3);
        e2 = findViewById(R.id.editText4);
        e3 = findViewById(R.id.editText5);
        b1 = findViewById(R.id.button4);

        progressDialog = new ProgressDialog(Question.this);
        progressDialog.setTitle("OSIX");
        progressDialog.setMessage("Saving Your Opinion.....");

        b1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final String question1 = e1.getText().toString();
                final String question2 = e2.getText().toString();
                final String question3 = e3.getText().toString();

                if (question1.isEmpty()){
                    e1.setError("Field is Empty");
                    e1.requestFocus();
                } else if (question2.isEmpty()){
                    e2.setError("Field is Empty");
                    e2.requestFocus();
                }else if (question3.isEmpty()){
                    e3.setError("Field is Empty");
                    e3.requestFocus();
                }else {
                    progressDialog.show();
                    user = mAuth.getCurrentUser();
                    assessment answer = new assessment(question1,question2,question3);
                    db.collection("Assessment").document().set(answer);
                    startActivity(new Intent(Question.this, Navbar.class));
                    progressDialog.show();
                }
            }
        });
    }
}

Use this way to get the uid of the current user:使用这种方式获取当前用户的uid

private FirebaseAuth firebaseAuth;
private FirebaseDatabase firebaseDatabase;
private DatabaseReference databaseReferenceRoot;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_question);

    firebaseAuth = FirebaseAuth.getInstance();
    firebaseDatabase = FirebaseDatabase.getInstance();
    databaseReferenceRoot = firebaseDatabase.getReference();
    String uid=firebaseAuth.getCurrentUser().getUid()
    //Here you get the uid

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Firebase电子邮件/密码身份验证获取UID并添加用户信息 - How to get UID and add user information with Firebase email/password authentication 如果我使用 facebook 进行身份验证,如何获取 firebase auth uid? - How get firebase auth uid if I'm using facebook for authentication? 如何获取 firebase Firestore 文档 ID - How to get the firebase firestore document id 如何匹配存储在 Firestore 的 Firebase 安全规则内的文档字段中的用户 uid - How to match a user's uid stored in document field inside Firebase security rule for Firestore 如何在 Firebase Firestore 中添加自动 uid 字段 - How to add auto uid field in Firebase Firestore Firebase 使用 UID 获取身份验证详细信息 - Firebase get Authentication details using UID 如何通过其uid获取Firestore用户列表? - How to get list of Firestore users by its uid? 如何下载 url 用于 firebase 存储和更新 Firestore 文档? - How to get download url for firebase storage and update firestore document? 要在Firestore DB中使用Firebase UID或令牌? - To Firebase UID or Token in Firestore DB? 如何在Firebase for Android中使用身份验证UId从用户节点获取用户信息? - How to get user information from user node using authentication UId in firebase for android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM