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"