From f37c48f1eef1ac67ac2194c78564f4c8ccf28689 Mon Sep 17 00:00:00 2001 From: Tracewebstudio Dev Date: Tue, 21 Apr 2026 21:51:02 +0200 Subject: [PATCH] fix: get_user_role_keys returns newest role first, not oldest - models/user.rs: ORDER BY ur.created_at DESC so most recently assigned role is returned first - handlers/auth.rs: resolve_signup_role_candidates returns empty vec instead of JOB_SEEKER when no valid intent --- apps/users/src/handlers/auth.rs | 21 +++++++++------------ crates/db/src/models/user.rs | 6 +++--- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/apps/users/src/handlers/auth.rs b/apps/users/src/handlers/auth.rs index 62dd5ba..bcedb1e 100644 --- a/apps/users/src/handlers/auth.rs +++ b/apps/users/src/handlers/auth.rs @@ -135,9 +135,13 @@ fn normalize_role_key(raw: &str) -> String { } fn resolve_signup_role_candidates(intent: Option<&str>, profession: Option<&str>) -> Vec { - let normalized_intent = normalize_role_key(intent.unwrap_or("JOB_SEEKER")); + let normalized_intent = intent.map(normalize_role_key).unwrap_or_default(); let normalized_profession = profession.map(normalize_role_key).filter(|v| !v.is_empty()); + if normalized_intent.is_empty() { + return vec![]; + } + if normalized_intent.contains("COMPANY") { return vec!["COMPANY".to_string()]; } @@ -154,7 +158,7 @@ fn resolve_signup_role_candidates(intent: Option<&str>, profession: Option<&str> return vec!["PHOTOGRAPHER".to_string(), "JOB_SEEKER".to_string()]; } - vec!["JOB_SEEKER".to_string()] + vec![] } fn role_display_name_from_code(code: &str) -> String { @@ -205,13 +209,6 @@ async fn ensure_role_exists(pool: &sqlx::PgPool, role_code: &str) -> Option Result, sqlx::Error> { let rows = sqlx::query_scalar::<_, String>( r#" SELECT r.key - FROM user_roles ur + FROM user_role_assignments ur JOIN roles r ON ur.role_id = r.id WHERE ur.user_id = $1 AND ur.status = 'APPROVED' - ORDER BY ur.created_at ASC + ORDER BY ur.created_at DESC "#, ) .bind(user_id)