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