Skip to content
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

FIX Password Reset Flow in SupaEmailAuth #89

Merged
merged 3 commits into from
May 13, 2024
Merged
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
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',
});
}
Loading