Skip to content

Commit e3de841

Browse files
author
Paul Philion
committed
added account delete button to profile page
1 parent db96f9a commit e3de841

File tree

6 files changed

+71
-0
lines changed

6 files changed

+71
-0
lines changed

src/support_sphere/lib/constants/string_catalog.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ class UserProfileStrings {
6565
static const String meetingPlace = 'Meeting place';
6666
static const String captains = 'Captain(s)';
6767
static const String submit = 'Submit';
68+
static const String deleteMyAccount = 'Delete My Account';
69+
static const String confirmPrompt = 'Please Confirm';
70+
static const String confirmAccountDelete = 'Are you sure you want to delete your account?';
71+
72+
6873
}
6974

7075
/// Checklist messages

src/support_sphere/lib/data/repositories/authentication.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ class AuthenticationRepository {
3333
}) async =>
3434
_authService.signInWithEmailAndPassword(email, password);
3535

36+
3637
Future<void> logOut() async => await _authService.signOut();
3738

39+
Future<void> deleteMyAccount() async => await _authService.deleteMyAccount();
40+
3841
Future<Map<String, dynamic>> signUp({
3942
required String email,
4043
required String password,

src/support_sphere/lib/data/services/auth_service.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ class AuthService extends Equatable{
4141
await _supabaseClient.rpc('invalidate_signup_code', params: {'input_code': code});
4242
}
4343

44+
// Delete the users account
45+
Future <void> deleteMyAccount() async {
46+
String? userId = _supabaseAuth.currentUser?.id;
47+
await _supabaseClient.rpc('delete_user', params: {'user_id': userId});
48+
}
49+
50+
// Delete an account
51+
Future <void> deleteUser(String userId) async {
52+
await _supabaseClient.rpc('delete_user', params: {'user_id': userId});
53+
}
54+
4455
Future<AuthResponse> signUpWithEmailAndPassword(String email, String password) async {
4556
// TODO: Add email verification in the future
4657
final response = await _supabaseAuth.signUp(email: email, password: password);

src/support_sphere/lib/logic/bloc/auth/authentication_bloc.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class AuthenticationBloc
1717
super(const AuthenticationState.initial()) {
1818
on<AuthOnCurrentUserChanged>(_onCurrentUserChanged);
1919
on<AuthOnLogoutRequested>(_onLogoutRequested);
20+
on<AuthDeleteMyUserRequested>(_onDeleteMyUserRequested);
2021

2122
_userSubscription = _authRepository.user.listen(
2223
(user) => add(AuthOnCurrentUserChanged(user)),
@@ -40,6 +41,11 @@ class AuthenticationBloc
4041
unawaited(_authRepository.logOut());
4142
}
4243

44+
void _onDeleteMyUserRequested(
45+
AuthDeleteMyUserRequested event, Emitter<AuthenticationState> emit) {
46+
unawaited(_authRepository.deleteMyAccount());
47+
}
48+
4349
@override
4450
Future<void> close() {
4551
_userSubscription.cancel();

src/support_sphere/lib/logic/bloc/auth/authentication_event.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ class AuthOnCurrentUserChanged extends AuthenticationEvent {
1010
}
1111

1212
class AuthOnLogoutRequested extends AuthenticationEvent {}
13+
14+
class AuthDeleteMyUserRequested extends AuthenticationEvent {}

src/support_sphere/lib/presentation/pages/main_app/profile/profile_body.dart

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class ProfileBody extends StatelessWidget {
5656
// _PrivacyAndNotifications(),
5757
// Log Out Button
5858
_LogOutButton(),
59+
_DeleteMyAccountButton(),
5960
],
6061
),
6162
),
@@ -88,6 +89,49 @@ class _LogOutButton extends StatelessWidget {
8889
}
8990
}
9091

92+
class _DeleteMyAccountButton extends StatelessWidget {
93+
const _DeleteMyAccountButton();
94+
95+
@override
96+
Widget build(BuildContext context) {
97+
return BlocBuilder<AuthenticationBloc, AuthenticationState>(
98+
builder: (context, state) {
99+
return Padding(
100+
padding: const EdgeInsets.all(10),
101+
child: ElevatedButton.icon(
102+
onPressed: () => showDialog(
103+
context: context,
104+
builder: (BuildContext ctx) {
105+
return AlertDialog(
106+
title: const Text(UserProfileStrings.confirmPrompt),
107+
content: const Text(UserProfileStrings.confirmAccountDelete),
108+
actions: [
109+
// Yes button
110+
TextButton(
111+
onPressed: () {
112+
// request delete
113+
context.read<AuthenticationBloc>().add(AuthDeleteMyUserRequested());
114+
115+
// Close the dialog
116+
Navigator.of(context).pop();
117+
},
118+
child: const Text(EmergencyAlertDialogStrings.buttonYes)),
119+
// No button
120+
TextButton(
121+
onPressed: () => Navigator.of(context).pop(),
122+
child: const Text(EmergencyAlertDialogStrings.buttonNo))
123+
],
124+
);
125+
}),
126+
icon: const Icon(Ionicons.trash_bin_outline),
127+
label: const Text(UserProfileStrings.deleteMyAccount),
128+
),
129+
);
130+
},
131+
);
132+
}
133+
}
134+
91135
class _PersonalInformation extends StatelessWidget {
92136
const _PersonalInformation();
93137

0 commit comments

Comments
 (0)