createUser static method

Future<UserInfo?> createUser(
  1. Session session,
  2. UserInfo userInfo, [
  3. String? authMethod
])

Creates a new user and stores it in the database.

Implementation

static Future<UserInfo?> createUser(
  Session session,
  UserInfo userInfo, [
  String? authMethod,
]) async {
  if (AuthConfig.current.onUserWillBeCreated != null) {
    var approved = await AuthConfig.current.onUserWillBeCreated!(
      session,
      userInfo,
      authMethod,
    );
    if (!approved) return null;
  }

  await session.db.insert(userInfo);
  if (userInfo.id != null) {
    if (AuthConfig.current.onUserCreated != null) {
      await AuthConfig.current.onUserCreated!(session, userInfo);
    }
    return userInfo;
  }
  return null;
}