Skip to content

Conversation

@Kilonzo88
Copy link

Hello! I've been following your tutorial and found it very helpful. I noticed that for new users, the project fails to compile due to a breaking change in a newer version of the validator crate.

The Problem

The project's Cargo.toml specifies validator = "0.16.1", which works correctly. However, a user starting the project today would likely get a newer version (e.g., 0.20.0) by default.

Starting with validator v0.17.0, duplicate validation attributes on a single field are no longer allowed and will cause a Duplicate field 'length' compilation error. This affects several of the password fields in axum_auth_backend/src/dtos.rs which use two length attributes.

There was also a minor field name mismatch, where FilterUserDto used name while the User model used username.

The Solution

This pull request updates the validation rules to conform to the modern API of the validator crate by removing redundant length attributes. It also corrects the name/username field mismatch for consistency.

Example Change:

// Old code (fails on validator v0.17+) #[validate(  length(min = 1, message = "Password is required"),  length(min = 6, message = "Password must be at least 6 characters") )] pub password: String, // Corrected code #[validate(length(min = 6, message = "Password must be at least 6 characters"))] pub password: String,

Benefits

  • Keeps Tutorial Current: Ensures the tutorial works "out-of-the-box" for new learners.
  • Fixes Compilation Errors: Resolves the build-blocking errors caused by the updated dependency.

This update will help keep your excellent tutorial accessible to everyone. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant