Skip to content

Commit d7538f4

Browse files
authored
FIX Password Reset Flow in SupaEmailAuth (#89)
* FIX #88 * Fix use of BuildContext's across async gaps * Fix use of BuildContext's across async gaps in SupaEmailAuth and SupaResetPassword
1 parent a77b19f commit d7538f4

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

lib/src/components/supa_email_auth.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,22 @@ class _SupaEmailAuthState extends State<SupaEmailAuth> {
298298
redirectTo: widget.redirectTo,
299299
);
300300
widget.onPasswordResetEmailSent?.call();
301+
// FIX use_build_context_synchronously
302+
if (!context.mounted) return;
303+
context.showSnackBar(localization.passwordResetSent);
304+
setState(() {
305+
_forgotPassword = false;
306+
});
301307
} on AuthException catch (error) {
302308
widget.onError?.call(error);
303309
} catch (error) {
304310
widget.onError?.call(error);
311+
} finally {
312+
if (mounted) {
313+
setState(() {
314+
_isLoading = false;
315+
});
316+
}
305317
}
306318
},
307319
child: Text(localization.sendPasswordReset),

lib/src/components/supa_reset_password.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ class _SupaResetPasswordState extends State<SupaResetPassword> {
7878
),
7979
);
8080
widget.onSuccess.call(response);
81+
// FIX use_build_context_synchronously
82+
if (!context.mounted) return;
83+
context.showSnackBar(localization.passwordResetSent);
8184
} on AuthException catch (error) {
8285
if (widget.onError == null && context.mounted) {
8386
context.showErrorSnackBar(error.message);

lib/src/localizations/supa_email_auth_localization.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class SupaEmailAuthLocalization {
99
final String dontHaveAccount;
1010
final String haveAccount;
1111
final String sendPasswordReset;
12+
final String passwordResetSent;
1213
final String backToSignIn;
1314
final String unexpectedError;
1415

@@ -24,6 +25,7 @@ class SupaEmailAuthLocalization {
2425
this.dontHaveAccount = 'Don\'t have an account? Sign up',
2526
this.haveAccount = 'Already have an account? Sign in',
2627
this.sendPasswordReset = 'Send password reset email',
28+
this.passwordResetSent = 'Password reset email has been sent',
2729
this.backToSignIn = 'Back to sign in',
2830
this.unexpectedError = 'An unexpected error occurred',
2931
});

lib/src/localizations/supa_reset_password_localization.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ class SupaResetPasswordLocalization {
33
final String passwordLengthError;
44
final String updatePassword;
55
final String unexpectedError;
6+
final String passwordResetSent;
67

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

0 commit comments

Comments
 (0)