update 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.

When updating scopes or the blocked status of an auth user, you may need to communicate these changes to the rest of the server using session.messages.authenticationRevoked with an appropriate message type (e.g., RevokedAuthenticationUser or RevokedAuthenticationScope).

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

Implementation

Future<AuthUserModel> update(
  final Session session, {
  required final UuidValue authUserId,
  final Set<Scope>? scopes,
  final bool? blocked,
  final Transaction? transaction,
}) async {
  return DatabaseUtil.runInTransactionOrSavepoint(session.db, transaction, (
    final 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();
  });
}