changeUserName static method

Future<UserInfo?> changeUserName(
  1. Session session,
  2. int userId,
  3. String newUserName
)

Updates a users name, returns null if unsuccessful.

Implementation

static Future<UserInfo?> changeUserName(
    Session session, int userId, String newUserName) async {
  var userInfo = await findUserByUserId(session, userId, useCache: false);
  if (userInfo == null) return null;

  userInfo.userName = newUserName;
  await session.db.update(userInfo);

  if (AuthConfig.current.onUserUpdated != null) {
    await AuthConfig.current.onUserUpdated!(session, userInfo);
  }

  await invalidateCacheForUser(session, userId);
  return userInfo;
}