2

I am developing a flutter firebase app, which will work for both retailer and admin user. When a retailer will download the app, he/she has to provide phone number auth details and all other mandatory details and has to submit. Admin will get the request and once admin approves, retailer will be able to login and will be able to see products. The admin app has extra features of creating retailers if a retailer is new to the app. Admin wants to add retailer from his app then Admin should provide retailer's phone auth and all other retailer details and user in firebase needs to be created.

Problem here is: Admin is giving the retailer's phone number and after giving OTP, the user for a retailer is getting created but after closing the admin app without signout, if the admin app is opened then the admin app shows Retailer details which was recently created by the admin, maybe because of cache.

I tried signing out of created user just after user is created but i could not find any method to signout specific users from app.

i expect the functionality of creating multiple firebase auth users from a single app.

Please find below the code Snippet.

String _userId = "";
  void _signInWithPhoneNumber() async {

    setState(() {
      _isLoading = true;
    });


    final AuthCredential credential1 = PhoneAuthProvider.getCredential(
      verificationId: _verificationId,
      smsCode: _smsCodeController.text,
    );
    try {
      final FirebaseUser user1 =
      (await db1.signInWithCredential(credential1));

      setState(() {
        _isLoading = false;
        _errorMessage = 'OTP verified Successfully !!';
        if (user1 != null) {
          print("Pranay Kumar value of newly created user  ${user1.uid}");
           db1.signOut();

          getCurrentUser().then((user) {
            setState(() {
              if (user != null) {
                _userId = user?.uid;
                print("Hello Pranay current Admin User $_userId");
              }
            });
          });

          print("Pranay Kumar value of newly created user  222  ${user1.uid}");
          Navigator.push(
              context,
              MaterialPageRoute(
                  builder: (context) =>
                      CreateCustomerDetailedPage(
                          userId: user1.uid,
                          phoneNumber: _phoneNumberController.text)));

          //getUserDetails(user.uid);
        } else {
          _isLoading = false;
          _errorMessage = 'Sign in failed';
        }
      });
    } catch (e) {
      print('Error: $e');
      setState(() {
        _isLoading = false;
        _errorMessage = e.message;
      });
    }
  }

  Future<FirebaseUser> getCurrentUser() async {
    FirebaseUser user = await FirebaseAuth.instance.currentUser();
    return user;
  }

After newly created user value of print statement becoming null which i does not want "Hello Pranay current Admin User"

  • This use-case isn't supported in the Firebase client SDK. While somebody found a work-around [here](https://stackoverflow.com/questions/37517208/firebase-kicks-out-current-user/38013551#38013551), it is precisely that: a work-around. To securely create users you should use the Admin SDK, which needs to be run in a trusted environment. See https://stackoverflow.com/questions/37517208/firebase-kicks-out-current-user – Frank van Puffelen Sep 08 '19 at 02:42
  • Frank van Puffelen --- Thank you for the response. I tried with workaround in flutter but still struggling. Can anyone please help me, how that workaround works in flutter..? – Pranay kumar Sep 08 '19 at 12:48
  • Although I haven't tried this workaround in Flutter myself, I checked that the relevant APIs are available there too. If you can't get it to work, edit your question to include the [minimum complete/standalone code that reproduces where you are stuck now](http://stackoverflow.com/help/mcve). – Frank van Puffelen Sep 08 '19 at 13:43
  • i have included the code snippet. Kindly help. – Pranay kumar Sep 08 '19 at 13:59
  • The code you shared is in no way creating a second `FirebaseApp` or `FirebaseAuth` instance as the linked question does. – Frank van Puffelen Sep 08 '19 at 14:43

0 Answers0