Skip to content

fix(firebase_ui_auth): actionsBeforeDelete callback #279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/firebase_ui_auth/lib/src/screens/profile_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,9 @@ class ProfileScreen extends MultiProviderScreen {
/// ```
final List<FirebaseUIAction>? actions;

// Any actions that should be performed before the account is deleted.
final ActionsBeforeDeleteCallback? actionsBeforeDelete;

/// See [Scaffold.appBar].
final AppBar? appBar;

Expand Down Expand Up @@ -751,6 +754,7 @@ class ProfileScreen extends MultiProviderScreen {
this.avatarSize,
this.children = const [],
this.actions,
this.actionsBeforeDelete,
this.appBar,
this.cupertinoNavigationBar,
this.actionCodeSettings,
Expand Down Expand Up @@ -917,6 +921,7 @@ class ProfileScreen extends MultiProviderScreen {
const SizedBox(height: 8),
DeleteAccountButton(
auth: auth,
actionsBeforeDelete: actionsBeforeDelete,
showDeleteConfirmationDialog: showDeleteConfirmationDialog,
onSignInRequired: () {
return _reauthenticate(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:flutter/material.dart';

typedef DeleteFailedCallback = void Function(Exception exception);
typedef SignInRequiredCallback = Future<bool> Function();
typedef ActionsBeforeDeleteCallback = Future<bool> Function();

/// {@template ui.auth.widgets.delete_account_button}
/// A button that triggers the deletion of the user's account.
Expand Down Expand Up @@ -55,6 +56,9 @@ class DeleteAccountButton extends StatefulWidget {
/// A callback that is called if the account deletion fails.
final DeleteFailedCallback? onDeleteFailed;

/// A callback that is called before the account is deleted.
final ActionsBeforeDeleteCallback? actionsBeforeDelete;

/// {@macro ui.shared.widgets.button_variant}
final ButtonVariant variant;

Expand All @@ -69,6 +73,7 @@ class DeleteAccountButton extends StatefulWidget {
this.auth,
this.onSignInRequired,
this.onDeleteFailed,
this.actionsBeforeDelete,
this.variant = ButtonVariant.filled,
this.showDeleteConfirmationDialog = false,
});
Expand Down Expand Up @@ -112,6 +117,13 @@ class _DeleteAccountButtonState extends State<DeleteAccountButton> {
});

try {
if (widget.actionsBeforeDelete != null) {
final proceed = await widget.actionsBeforeDelete!();
if (!proceed) {
throw Exception('Can not complete actions before delete.');
}
}

final user = auth.currentUser!;
await auth.currentUser?.delete();

Expand Down