Skip to content

Commit

Permalink
Add New Field to validate password (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
jadl456 authored Oct 25, 2024
1 parent 2f38b5d commit 99513e9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/src/components/supa_email_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ class SupaEmailAuth extends StatefulWidget {
final Widget? prefixIconEmail;
final Widget? prefixIconPassword;

/// Whether the confirm password field should be displayed
final bool showConfirmPasswordField;

/// {@macro supa_email_auth}
const SupaEmailAuth({
super.key,
Expand All @@ -232,6 +235,7 @@ class SupaEmailAuth extends StatefulWidget {
this.isInitiallySigningIn = true,
this.prefixIconEmail = const Icon(Icons.email),
this.prefixIconPassword = const Icon(Icons.lock),
this.showConfirmPasswordField = false,
});

@override
Expand All @@ -242,6 +246,7 @@ class _SupaEmailAuthState extends State<SupaEmailAuth> {
final _formKey = GlobalKey<FormState>();
final _emailController = TextEditingController();
final _passwordController = TextEditingController();
final _confirmPasswordController = TextEditingController();
late bool _isSigningIn;
late final Map<String, MetadataController> _metadataControllers;

Expand Down Expand Up @@ -271,6 +276,7 @@ class _SupaEmailAuthState extends State<SupaEmailAuth> {
void dispose() {
_emailController.dispose();
_passwordController.dispose();
_confirmPasswordController.dispose();
for (final controller in _metadataControllers.values) {
if (controller is TextEditingController) {
controller.dispose();
Expand Down Expand Up @@ -345,6 +351,23 @@ class _SupaEmailAuthState extends State<SupaEmailAuth> {
}
},
),
if (widget.showConfirmPasswordField && !_isSigningIn) ...[
spacer(16),
TextFormField(
controller: _confirmPasswordController,
decoration: InputDecoration(
prefixIcon: widget.prefixIconPassword,
label: Text(localization.confirmPassword),
),
obscureText: true,
validator: (value) {
if (value != _passwordController.text) {
return localization.confirmPasswordError;
}
return null;
},
),
],
spacer(16),
if (widget.metadataFields != null && !_isSigningIn)
...widget.metadataFields!
Expand Down
4 changes: 4 additions & 0 deletions lib/src/localizations/supa_email_auth_localization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class SupaEmailAuthLocalization {
final String backToSignIn;
final String unexpectedError;
final String requiredFieldError;
final String confirmPasswordError;
final String confirmPassword;

const SupaEmailAuthLocalization({
this.enterEmail = 'Enter your email',
Expand All @@ -30,5 +32,7 @@ class SupaEmailAuthLocalization {
this.backToSignIn = 'Back to sign in',
this.unexpectedError = 'An unexpected error occurred',
this.requiredFieldError = 'This field is required',
this.confirmPasswordError = 'Passwords do not match',
this.confirmPassword = 'Confirm Password',
});
}

0 comments on commit 99513e9

Please sign in to comment.