onSignOut method

Future<void> onSignOut()

Implementation

Future<void> onSignOut() async {
  fn.cancelAll();
  try {
    String? currentToken = await FirebaseMessaging.instance.getToken();
    if (currentToken == null) {
      info("No FCM token found for sign out.");
      return;
    }

    warn("Removing FCM Token");
    String hash = hashFCM(currentToken);
    List<FCMDeviceInfo> d = await readUserDevices($uid!);
    d.removeWhere((i) => i.hash == hash);
    await Future.wait([
      writeUserDevices($uid!, d),
      FirebaseMessaging.instance.deleteToken(),
    ], eagerError: false);

    success(
      "Successfully signed out token fcm & removed fcm tokens & hashes from user for this device.",
    );
  } catch (e, es) {
    error("Failed to sign out token fcm");
    error(es);
  }
}