Skip to content

Commit

Permalink
Add passwordValidator field to SupaEmailAuth to allow custom password…
Browse files Browse the repository at this point in the history
… validation (#121)
  • Loading branch information
bcorman authored Oct 11, 2024
1 parent 726f55e commit 254d09a
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lib/src/components/supa_email_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -209,6 +215,7 @@ class SupaEmailAuth extends StatefulWidget {
super.key,
this.redirectTo,
this.resetPasswordRedirectTo,
this.passwordValidator,
required this.onSignInComplete,
required this.onSignUpComplete,
this.onPasswordResetEmailSent,
Expand Down Expand Up @@ -313,12 +320,13 @@ class _SupaEmailAuthState extends State<SupaEmailAuth> {
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),
Expand Down

0 comments on commit 254d09a

Please sign in to comment.