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

Feature: add custom password validation to SupaEmailAuth form #121

Merged
merged 1 commit into from
Oct 11, 2024
Merged
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
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
Loading