feat: Auto Keycloak account creation on registration + fix email-mismatch bug + fix account script names #93
Labels
No labels
domain:backend
domain:devops
domain:frontend
status:approved
status:in-progress
status:needs-fix
status:qa
type:bug
type:devops
type:feature
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
forgejo_admin/basketball-api#93
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Lineage
plan-wkq→ Phase 11 (Girls Tryout — March 21)Repo
forgejo_admin/basketball-apiUser Story
As a parent registering my child for tryouts,
I want my Keycloak account to be created automatically after I pay,
So that I can log in immediately without waiting for a manual batch script.
Context
Three fixes bundled because they're tightly coupled — all relate to the registration → account creation pipeline.
Bug 1: Email-mismatch (register.py:796)
The registration POST handler looks up parents by
Parent.email == parent_email. If a parent uses a different email than what was used in Stripe checkout, a new parent record is created — the waiver lands on the wrong parent. This happened during March 13 tryout. Fix: when a registration token is present, match byParent.registration_token == token. Only fall back to email for the walk-up (no-token) flow.Bug 2: Account creation script missing names (create_keycloak_accounts.py:113)
The
create_keycloak_user()function payload doesn't includefirstName/lastName. This causes Keycloak to enforceVERIFY_PROFILErequired action on first login, forcing every parent to fill in their name. The parent name data IS available —_parent_nameis passed inget_paid_families()at line 270 but ignored in the payload. Workaround was applied March 14 (backfilled 50 accounts via Admin API), but the script is still broken for future runs.Feature: Auto Keycloak account creation in registration flow
After a parent completes registration with successful Stripe payment, automatically create their Keycloak account via the Keycloak Admin API. This eliminates the manual batch script (
scripts/create_keycloak_accounts.py) for the happy path. The script remains for edge cases (backfills, cash payments marked paid later by admin).Architecture decision: The registration flow is backend (basketball-api). This integration survives the upcoming SSR → SPA frontend migration (Phase 15). Building it correctly now means it serves both the current app and the future SPA.
Keycloak config:
https://keycloak.tail5b443a.ts.netwestside-basketballKEYCLOAK_ADMIN_PASSWORDenv var (already available in the pod)admin,coach,player(all realm roles, already exist)draneylucas@gmail.com,mldraney3@gmail.comFile Targets
Files to modify:
src/basketball_api/routes/register.py— fix email-mismatch (line 796 area), add auto Keycloak account creation after successful paymentscripts/create_keycloak_accounts.py— addfirstName/lastNametocreate_keycloak_user()payload (line 113 area)src/basketball_api/config.py— addKEYCLOAK_BASE_URL,KEYCLOAK_ADMIN_PASSWORDconfig vars if not already presentFiles to create:
src/basketball_api/services/keycloak.py— extract Keycloak Admin API operations (create user, assign role, check existing) into a reusable service module. Reuse the logic fromscripts/create_keycloak_accounts.py— don't duplicate it.Files NOT to touch:
src/basketball_api/routes/teams.py— unrelatedsrc/basketball_api/routes/players.py— unrelatedsrc/basketball_api/routes/subscriptions.py— Stripe subscription management is separateAcceptance Criteria
playerrole, firstName/lastName set)create_keycloak_accounts.py, new accounts includefirstName/lastName(no VERIFY_PROFILE prompt)Test Expectations
test_register_token_lookup— registration with token uses token-based parent lookup, not emailtest_register_auto_keycloak_account— successful paid registration creates Keycloak user with correct firstName, lastName, roletest_register_duplicate_keycloak_skip— if Keycloak user already exists, skip without errortest_register_unpaid_no_keycloak— unpaid registration does NOT create Keycloak accounttest_keycloak_script_includes_names— batch script payload includes firstName/lastNamepytest tests/ -vConstraints
register.py— the file uses inline HTML rendering, keep that stylescripts/password_gen.py(generate_password(first_name)) — import it or move to a shared locationhttpx(already a dependency) for both.Checklist
Related
project-westside-basketball— project this affects