I had the same problem. Firebase stores the current auth user information in Keychain (instead of shared preferences / userdefaults)
I found a solution somewhere online (forgive me, I don't know who to credit), where the work around was to check if the app had run at least once (persisted on device - because that will not persist across installations). If it had not run yet, log the user out. If it had run, nothing. My implementation looks like this:
import 'package:app/main.dart' as main;
import 'package:firebase_auth/firebase_auth.dart';
import 'package:shared_preferences/shared_preferences.dart';
abstract class AppHelper {
static firstRunCheck() async {
// purpose of what we're doing here is clearing out the keychain items across
// installations (they persist after installations)
final SharedPreferences sharedPreferences = main.getIt<SharedPreferences>();
const String hasRunBeforePrefKey = 'localStorage.hasRunBefore';
final bool hasRunBefore = sharedPreferences.getBool(hasRunBeforePrefKey) ?? false;
if(hasRunBefore) {
return;
}
await sharedPreferences.setBool(hasRunBeforePrefKey, true);
User? currentUser = FirebaseAuth.instance.currentUser;
if(currentUser != null) {
await FirebaseAuth.instance.signOut();
}
}
}
And then I just add this in my main.dart
await AppHelper.firstRunCheck();