createUser static method

Future<UserInfo?> createUser(
  1. Session session,
  2. UserInfo userInfo, [
  3. String? authMethod,
  4. UserInfoCreationCallback? onUserWillBeCreatedOverride,
  5. UserInfoUpdateCallback? onUserCreatedOverride,
])

Creates a new user and stores it in the database.

Implementation

static Future<UserInfo?> createUser(
  Session session,
  UserInfo userInfo, [
  String? authMethod,
  UserInfoCreationCallback? onUserWillBeCreatedOverride,
  UserInfoUpdateCallback? onUserCreatedOverride,
]) async {
  bool approved = switch (onUserWillBeCreatedOverride) {
    null => await AuthConfig.current.onUserWillBeCreated?.call(
          session,
          userInfo,
          authMethod,
        ) ??
        true,
    _ => await onUserWillBeCreatedOverride.call(session, userInfo, authMethod)
  };
  if (!approved) return null;

  userInfo = await UserInfo.db.insertRow(session, userInfo);

  if (onUserCreatedOverride == null) {
    await AuthConfig.current.onUserCreated?.call(session, userInfo);
  } else {
    await onUserCreatedOverride(session, userInfo);
  }

  return userInfo;
}