【问题标题】:how to change firebase user in andorid [duplicate]如何在android中更改firebase用户[重复]
【发布时间】:2020-01-02 02:29:03
【问题描述】:

我开发了一个具有组管理员的应用程序,该组管理员可以通过使用 firebase 签名来加入用户,并且在管理员签名后我希望该应用程序将重新登录给管理员(该应用程序可能有多个管理员-一个用于每组), 我试图保存 currfirebase 用户然后切换回来,但是当 firebaseauth 更改它时,它会自动更改为 pervous 用户,我什至让他成为最终用户,但它没有帮助

private final FirebaseUser currUser = currUserauth.getCurrentUser();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_contact);
        db = FirebaseFirestore.getInstance();

        Button addContactBtn = findViewById(R.id.add_contact_btn);
        progressBar = findViewById(R.id.add_content_progressbar);


            userEmailEt = findViewById(R.id.et_email);
            passwordEt = findViewById(R.id.et_password);
            confirmBtnEt = findViewById(R.id.confirmBtn);
        nameEt = findViewById(R.id.add_contact_name_et);

        addContactBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                addNewContact();
            }
        });
    }

    private void addNewContact() {

        progressBar.setVisibility(View.VISIBLE);

        final String email = userEmailEt.getText().toString();
        String password = passwordEt.getText().toString().trim();
        final String name = nameEt.getText().toString();

        if (!Patterns.EMAIL_ADDRESS.matcher(email).matches() || email.equals("")) {
            userEmailEt.setError("Email is not valid");
        } else if (TextUtils.isEmpty(password)) {
            passwordEt.setError("password is not valid");
        } else if(TextUtils.isEmpty(name)){
            nameEt.setError("נא למלא שם");
        }else {

            mAuth.createUserWithEmailAndPassword(email, password)
                    .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                        @Override
                        public void onComplete(@NonNull Task<AuthResult> task) {
                            if (task.isSuccessful()) {
                                // Sign in success, update UI with the signed-in user's information

                                FirebaseUser firebaseUser = mAuth.getCurrentUser();
                                Toast.makeText(getApplicationContext(), "User created successfully", Toast.LENGTH_SHORT).show();

    update();
                                progressBar.setVisibility(View.GONE);

                                mAuth.signOut();


                                mAuth.updateCurrentUser(currUser).addOnCompleteListener(new OnCompleteListener<Void>() {
                                    @Override
                                    public void onComplete(@NonNull Task<Void> task) {
                                mAuth.getCurrentUser().reload().addOnCompleteListener(new OnCompleteListener<Void>() {
                                    @Override
                                    public void onComplete(@NonNull Task<Void> task) {

                                        Intent intent = new Intent(getApplicationContext(), ContactActivity.class);
                                        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                        System.out.println("From addContactActivity: " + mAuth.getCurrentUser().getEmail());
                                        startActivity(intent);
                                        finish();
                                    }
                                });

【问题讨论】:

    标签: android firebase firebase-authentication


    【解决方案1】:

    用户帐户无法在前端的 Firebase 身份验证中创建其他用户帐户。此外,一次只能登录一个用户。

    您尝试做的最适合在您控制的后端上运行,使用Firebase Admin SDKcreate the user accounts

    【讨论】:

      猜你喜欢
      • 2021-09-24
      • 2020-09-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-22
      • 2021-09-28
      • 1970-01-01
      • 2021-09-04
      • 2020-08-15
      相关资源
      最近更新 更多