delete method
Removes the specified auth user.
This also removes all authentication-related entities from all
serverpod_auth_* packages which are linked to this user, like the
various authentication methods and sessions.
(This is based on the onDelete=Cascade relationship between the models.
Other packages linking to the AuthUser may or may not opt into this.)
When deleting an auth user, you may need to communicate this revocation
to the rest of the server using session.messages.authenticationRevoked
with RevokedAuthenticationUser.
Throws an AuthUserNotFoundException in case no auth user is found for the ID.
Implementation
Future<void> delete(
final Session session, {
required final UuidValue authUserId,
final Transaction? transaction,
}) async {
return DatabaseUtil.runInTransactionOrSavepoint(session.db, transaction, (
final transaction,
) async {
final deletedUsers = await AuthUser.db.deleteWhere(
session,
where: (final t) => t.id.equals(authUserId),
transaction: transaction,
);
if (deletedUsers.isEmpty) {
throw AuthUserNotFoundException();
}
});
}