From 254d09ad3ea6d15069dceaf0c2ba3f24f86ec50e Mon Sep 17 00:00:00 2001 From: Ben Corman Date: Fri, 11 Oct 2024 04:02:37 -0700 Subject: [PATCH] Add passwordValidator field to SupaEmailAuth to allow custom password validation (#121) --- lib/src/components/supa_email_auth.dart | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/src/components/supa_email_auth.dart b/lib/src/components/supa_email_auth.dart index c91a3f2..0ed1501 100644 --- a/lib/src/components/supa_email_auth.dart +++ b/lib/src/components/supa_email_auth.dart @@ -165,6 +165,12 @@ class SupaEmailAuth extends StatefulWidget { /// If unspecified, the [redirectTo] value will be used. final String? resetPasswordRedirectTo; + /// Validator function for the password field + /// + /// If null, a default validator will be used that checks if + /// the password is at least 6 characters long. + final String? Function(String?)? passwordValidator; + /// Callback for the user to complete a sign in. final void Function(AuthResponse response) onSignInComplete; @@ -209,6 +215,7 @@ class SupaEmailAuth extends StatefulWidget { super.key, this.redirectTo, this.resetPasswordRedirectTo, + this.passwordValidator, required this.onSignInComplete, required this.onSignUpComplete, this.onPasswordResetEmailSent, @@ -313,12 +320,13 @@ class _SupaEmailAuthState extends State { textInputAction: widget.metadataFields != null && !_isSigningIn ? TextInputAction.next : TextInputAction.done, - validator: (value) { - if (value == null || value.isEmpty || value.length < 6) { - return localization.passwordLengthError; - } - return null; - }, + validator: widget.passwordValidator ?? + (value) { + if (value == null || value.isEmpty || value.length < 6) { + return localization.passwordLengthError; + } + return null; + }, decoration: InputDecoration( prefixIcon: widget.prefixIconPassword, label: Text(localization.enterPassword),