ensureUserID method

Future<User> ensureUserID(
  1. User user
)

Ensures that a User object has a valid ID.

If the User object has no ID set, this method attempts to find the user by their username and assigns the ID.

  • user: The User object that needs an ID.

Returns the updated User object with a valid ID.

Implementation

Future<User> ensureUserID(User user) async {
  if (user.ID == 0) {
    User? userByName = await getUserByName(user.userName);
    return userByName!;
  } else {
    return user;
  }
}