fix(auth): default role assignment to APPROVED at signup
All checks were successful
build-and-release / build (fitness-trainers) (push) Successful in 3s
build-and-release / build (catering-services) (push) Successful in 13s
build-and-release / build (customers) (push) Successful in 12s
build-and-release / build (gateway) (push) Successful in 4s
build-and-release / build (employees) (push) Successful in 14s
build-and-release / build (graphic-designers) (push) Successful in 3s
build-and-release / build (cron) (push) Successful in 16s
build-and-release / build (job-seekers) (push) Successful in 5s
build-and-release / build (jobs) (push) Successful in 3s
build-and-release / build (leads) (push) Successful in 5s
build-and-release / build (payments) (push) Successful in 3s
build-and-release / build (makeup-artists) (push) Successful in 5s
build-and-release / build (photographers) (push) Successful in 5s
build-and-release / build (tutors) (push) Successful in 4s
build-and-release / build (social-media-managers) (push) Successful in 4s
build-and-release / build (ugc-content-creators) (push) Successful in 5s
build-and-release / build (video-editors) (push) Successful in 4s
build-and-release / build (users) (push) Successful in 7m30s
build-and-release / build (companies) (push) Successful in 9s
build-and-release / build (developers) (push) Successful in 8s

Roles assigned at registration are immediately active for login + session.
Document/profile approval (handled separately by user_role_profiles in
onboarding/verifications) is the correct gate for review workflows —
do not gate raw role assignment on that flow.

Previously defaulted to PENDING for non-demo accounts, which get filtered
out by get_user_role_keys (WHERE status = 'APPROVED') and produced JWTs
with empty roles, causing the 'role is not assigned' UX bug after login.
This commit is contained in:
Ashwin Kumar Sivakumar 2026-07-09 23:41:49 +05:30
parent f7d0f6f9f5
commit 9d475858ab

View file

@ -330,14 +330,19 @@ async fn register(
for role_key in role_candidates {
let role_id = ensure_role_exists(&state.pool, &role_key).await;
if let Some(role_id) = role_id {
// For demo accounts, auto-approve the role immediately
let status = if is_demo_account { "APPROVED" } else { "PENDING" };
// Roles assigned at signup are immediately ACTIVE for login + session.
// Document/profile review (handled separately in onboarding / verifications)
// still uses PENDING_APPROVAL via user_role_profiles — do NOT gate raw
// role assignment on that flow. Previously this defaulted to "PENDING"
// which made get_user_role_keys return [] and login issued a JWT with
// no role, breaking the "role not assigned" UX bug.
let status = "APPROVED";
// Try to update existing assignment first
let update_result = sqlx::query(
r#"
UPDATE user_role_assignments
SET status = $3
SET status = $3, approved_at = NOW()
WHERE user_id = $1 AND role_id = $2
"#,
)