update static method

Future<AuthUserModel> update(
  1. Session session, {
  2. required UuidValue authUserId,
  3. Set<Scope>? scopes,
  4. bool? blocked,
  5. Transaction? transaction,
})

Updates an auth user.

Throws an AuthUserNotFoundException in case no auth user is found for the ID.

Implementation

static Future<AuthUserModel> update(
  final Session session, {
  required final UuidValue authUserId,
  final Set<Scope>? scopes,
  final bool? blocked,
  final Transaction? transaction,
}) async {
  var authUser = await AuthUser.db.findById(
    session,
    authUserId,
    transaction: transaction,
  );
  if (authUser == null) {
    throw AuthUserNotFoundException();
  }

  if (scopes != null) {
    authUser = authUser.copyWith(
      scopeNames: scopes.map((final s) => s.name).nonNulls.toSet(),
    );
  }

  if (blocked != null) {
    authUser = authUser.copyWith(
      blocked: blocked,
    );
  }

  authUser = await AuthUser.db.updateRow(
    session,
    authUser,
    transaction: transaction,
  );

  return authUser.toModel();
}