email is now required
This commit is contained in:
@@ -11,6 +11,11 @@ pub async fn register(
|
||||
pool: &PgPool,
|
||||
payload: RegisterRequest,
|
||||
) -> Result<Response<AuthResponse>, Status> {
|
||||
// Validate required fields
|
||||
if payload.email.trim().is_empty() {
|
||||
return Err(Status::invalid_argument("Email is required"));
|
||||
}
|
||||
|
||||
// Validate passwords match
|
||||
if payload.password != payload.password_confirmation {
|
||||
return Err(Status::invalid_argument(AuthError::PasswordMismatch.to_string()));
|
||||
@@ -41,6 +46,15 @@ pub async fn register(
|
||||
if db_err.constraint() == Some("valid_roles") {
|
||||
return Status::invalid_argument(format!("Invalid role specified: '{}'", role_to_insert));
|
||||
}
|
||||
// Check for specific constraint violations
|
||||
if let Some(constraint) = db_err.constraint() {
|
||||
if constraint.contains("users_username_key") {
|
||||
return Status::already_exists("Username already exists".to_string());
|
||||
}
|
||||
if constraint.contains("users_email_key") {
|
||||
return Status::already_exists("Email already exists".to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
if e.to_string().contains("duplicate key") {
|
||||
Status::already_exists(AuthError::UserExists.to_string())
|
||||
|
||||
Reference in New Issue
Block a user