getLoggedInUser method

Future<User?> getLoggedInUser()

Fetches the logged-in user information from shared preferences.

This method retrieves the last logged-in username and password from shared preferences and attempts to authenticate the user using these credentials. It returns the User object if found, or null if no user is logged in.

Returns a Future that completes with the logged-in User or null.ds, or null otherwise.

Implementation

Future<User?> getLoggedInUser() async {
  String savedUserName = await sharedPref.get("lastLoggedInUserName");
  String savedPassword = await sharedPref.get("lastLoggedInUserPassword");

  if (savedUserName.isEmpty || savedPassword.isEmpty) return null;

  String savedPasswordHash = encryptionUtils.hashUserPassword(
      passwordToHash: savedPassword, userName: savedUserName);

  return await dataHandler.getUserRepo().getUser(
      userName: savedUserName, hashedPassword: savedPasswordHash);
}