# Role assignment Detail for the **role** step. Source of truth: reference `org-setup.mjs` `assignRoleToCurrentUser` (743-822). Run this step **only** when a role is configured (`role: { assignee: "currentUser", roleName: "" }` in `org-setup.config.json`). If absent, no-op cleanly. `assignee` is always `currentUser` — it is the only value the flow honors. Assigning a role to the current user is what makes Experience Cloud self-registration work correctly, so this step normally runs before/with self-reg. Validate `roleName` against the SOQL-name whitelist before querying. ## Sequence 1. **Resolve the role Id**: ```sql SELECT Id FROM UserRole WHERE Name = '' ``` Zero rows → hard error (`role "" not found in org`). 2. **Resolve the current user**: `sf org display --target-org --json` → `result.username`. If absent → hard error. 3. **Idempotency check**: ```sql SELECT Id, UserRoleId FROM User WHERE Username = '' ``` If `UserRoleId` is already set, **skip** — do not override an existing role assignment (lines 796-805). 4. **Assign**: ```bash sf data update record --sobject User \ --where "Username=''" \ --values "UserRoleId=''" \ --target-org --json ``` Non-zero exit → hard error (`failed to assign role "" to `).