deleteCurrentUser method
Deletes the authenticated principal's own account permanently
(DELETE /users/me).
This is the robust default for GDPR right-to-erasure: it cannot target the wrong account because the server resolves "me" from the auth token, so no caller-supplied id is involved. Irreversible — the backend tombstones messages but removes the profile record; managed users belonging to this principal are cascaded out too.
Prefer this over delete for self-service account deletion. After it succeeds you should tear the client down (ChatClient.dispose) and drive the host app back to its sign-out / onboarding flow, since the credential now points at a deleted account.
final res = await client.users.deleteCurrentUser();
res.fold(
(failure) => showError(failure),
(_) async {
await chat.dispose();
goToOnboarding();
},
);
Implementation
@override
Future<ChatResult<void>> deleteCurrentUser() async {
_client._users.remove(_client.currentUserId);
return const ChatSuccess(null);
}