deleteAccount method
Permanently deletes the current user's account.
The server-side deletion runs before local sign-out so it still has an authenticated token. Sign-out is best-effort after the identity is gone.
Implementation
Future<void> deleteAccount() async {
state = const AsyncLoading();
state = await AsyncValue.guard(() async {
final userId = ref.read(currentUserProvider)?.id;
await ref.read(profileRepositoryProvider).deleteAccount();
if (userId != null) {
await deleteUserData(ref, userId);
// Unlike a sign-out, this is the end of the account, so the games it
// played on this device go with it.
await deleteLocalGamesFor(ref, userId);
}
try {
await ref.read(authServiceProvider).signOut();
} catch (error) {
developer.log(
'Sign-out after account deletion failed (ignored)',
name: 'auth.controller',
error: error,
);
}
});
}