0

im devlop an app that has group admin, this group admin can join user by sign them with firebase, and after the admin sign them i want the app will sign back to the admin(the app could have multiple admin- one for each group), i tried to save the currfirebase user and then switch back but when firebaseauth is change it change automaticlly the pervous user, i even make him final but it didt help

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();
                                    }
                                });
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
koby
  • 29
  • 6

1 Answers1

1

User accounts can't create other user accounts in Firebase Authentication on the frontend. Also, only one user can be signed in at a time.

What you're trying to do is best suited to run on a backend you control, using the Firebase Admin SDK to create the user accounts.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441