Skip to content

Commit

Permalink
FIX Password Reset Flow in SupaEmailAuth (#89)
Browse files Browse the repository at this point in the history
* FIX #88

* Fix use of BuildContext's across async gaps

* Fix use of BuildContext's across async gaps in SupaEmailAuth and SupaResetPassword
  • Loading branch information
henry2man authored May 13, 2024
1 parent a77b19f commit d7538f4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/src/components/supa_email_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,22 @@ class _SupaEmailAuthState extends State<SupaEmailAuth> {
redirectTo: widget.redirectTo,
);
widget.onPasswordResetEmailSent?.call();
// FIX use_build_context_synchronously
if (!context.mounted) return;
context.showSnackBar(localization.passwordResetSent);
setState(() {
_forgotPassword = false;
});
} on AuthException catch (error) {
widget.onError?.call(error);
} catch (error) {
widget.onError?.call(error);
} finally {
if (mounted) {
setState(() {
_isLoading = false;
});
}
}
},
child: Text(localization.sendPasswordReset),
Expand Down
3 changes: 3 additions & 0 deletions lib/src/components/supa_reset_password.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ class _SupaResetPasswordState extends State<SupaResetPassword> {
),
);
widget.onSuccess.call(response);
// FIX use_build_context_synchronously
if (!context.mounted) return;
context.showSnackBar(localization.passwordResetSent);
} on AuthException catch (error) {
if (widget.onError == null && context.mounted) {
context.showErrorSnackBar(error.message);
Expand Down
2 changes: 2 additions & 0 deletions lib/src/localizations/supa_email_auth_localization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class SupaEmailAuthLocalization {
final String dontHaveAccount;
final String haveAccount;
final String sendPasswordReset;
final String passwordResetSent;
final String backToSignIn;
final String unexpectedError;

Expand All @@ -24,6 +25,7 @@ class SupaEmailAuthLocalization {
this.dontHaveAccount = 'Don\'t have an account? Sign up',
this.haveAccount = 'Already have an account? Sign in',
this.sendPasswordReset = 'Send password reset email',
this.passwordResetSent = 'Password reset email has been sent',
this.backToSignIn = 'Back to sign in',
this.unexpectedError = 'An unexpected error occurred',
});
Expand Down
2 changes: 2 additions & 0 deletions lib/src/localizations/supa_reset_password_localization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ class SupaResetPasswordLocalization {
final String passwordLengthError;
final String updatePassword;
final String unexpectedError;
final String passwordResetSent;

const SupaResetPasswordLocalization({
this.enterPassword = 'Enter your password',
this.passwordLengthError =
'Please enter a password that is at least 6 characters long',
this.updatePassword = 'Update Password',
this.unexpectedError = 'An unexpected error occurred',
this.passwordResetSent = 'Password reset email has been sent',
});
}

0 comments on commit d7538f4

Please sign in to comment.