Skip to content
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
63 changes: 43 additions & 20 deletions packages/firebase_ui_auth/lib/src/screens/profile_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -224,18 +224,24 @@ class _LinkedProvidersRowState extends State<_LinkedProvidersRow> {
await user.unlink(providerId);
await user.reload();

if (!mounted) return;

setState(() {
widget.onProviderUnlinked();
isEditing = false;
});
} on fba.FirebaseAuthException catch (e) {
setState(() {
error = e;
});
if (mounted) {
setState(() {
error = e;
});
}
} finally {
setState(() {
unlinkingProvider = null;
});
if (mounted) {
setState(() {
unlinkingProvider = null;
});
}
}
}

Expand Down Expand Up @@ -564,6 +570,8 @@ class _MFAToggleState extends State<_MFAToggle> {
final mfa = widget.auth.currentUser!.multiFactor;
final factors = await mfa.getEnrolledFactors();

if (!mounted) return;

if (factors.isEmpty) {
setState(() {
isLoading = false;
Expand All @@ -573,23 +581,29 @@ class _MFAToggleState extends State<_MFAToggle> {

try {
await mfa.unenroll(multiFactorInfo: factors.first);
if (!mounted) return;
widget.onToggled?.call();
} on PlatformException catch (e) {
if (e.code == 'FirebaseAuthRecentLoginRequiredException') {
if (await _reauthenticate()) {
if (!mounted) return;
if (await _reauthenticate() && mounted) {
await _disable();
}
} else {
rethrow;
}
} on Exception catch (e) {
setState(() {
exception = e;
});
if (mounted) {
setState(() {
exception = e;
});
}
} finally {
setState(() {
isLoading = false;
});
if (mounted) {
setState(() {
isLoading = false;
});
}
}
}

Expand Down Expand Up @@ -618,24 +632,33 @@ class _MFAToggleState extends State<_MFAToggle> {

try {
await mfa.enroll(assertion);
if (!mounted) return;
widget.onToggled?.call();
} on Exception catch (e) {
setState(() {
exception = e;
});
if (mounted) {
setState(() {
exception = e;
});
}
} finally {
setState(() {
isLoading = false;
});
if (mounted) {
Comment thread
BurningAXE marked this conversation as resolved.
setState(() {
isLoading = false;
});
}

if (context.mounted) {
// If currentRoute was removed, popUntil would never find it and
// would pop every route.
if (context.mounted && (currentRoute?.isActive ?? false)) {
Navigator.of(context).popUntil((route) => route == currentRoute);
}
}
}),
],
);

if (!mounted) return;

setState(() {
isLoading = false;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class _DeleteAccountButtonState extends State<DeleteAccountButton> {
}
}

if (!(confirmed ?? false)) return;
if (!(confirmed ?? false) || !mounted) return;

setState(() {
_isLoading = true;
Expand All @@ -134,6 +134,7 @@ class _DeleteAccountButtonState extends State<DeleteAccountButton> {
await FirebaseUIAuth.signOut(context: context, auth: auth);
} on fba.FirebaseAuthException catch (err) {
if (err.code == 'requires-recent-login') {
if (!mounted) return;
if (widget.onSignInRequired != null) {
final signedIn = await widget.onSignInRequired!();
if (signedIn) {
Expand All @@ -144,9 +145,11 @@ class _DeleteAccountButtonState extends State<DeleteAccountButton> {
} on Exception catch (e) {
widget.onDeleteFailed?.call(e);
} finally {
setState(() {
_isLoading = false;
});
if (mounted) {
Comment thread
BurningAXE marked this conversation as resolved.
setState(() {
_isLoading = false;
});
}
}
}

Expand Down
Loading
Loading