1

This problem i found on rel device, not on emulator. I complete login with phoneNumber, complete logout, delete and install app again and FirebaseAuth.getCurrentUser() give me this user again. How about deleting the application, despite the fact that before deleting I LOG out of the account, after reinstalling the application, FirebaseAuth.getCurrentUser() gives this user again?

UPD: User is stuck is logged with Microsoft

rulila52
  • 111
  • 1
  • 6
  • I think this is also related to https://stackoverflow.com/questions/27893418/firebase-deleting-and-reinstalling-app-does-not-un-authenticate-a-user?rq=1 ? – Berci Oct 18 '21 at 21:18

1 Answers1

3

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();
Jared Anderton
  • 826
  • 9
  • 12