Skip to main content

core-user-service

Manages internal user records. Each user in this service maps to a Better Auth user via betterAuthUserId and belongs to exactly one organization. Provides user CRUD, profile management, permissions, search, and the builder pattern for onboarding.

Worker name: crow-core-user-service Domain (prod): internal.users.crowai.dev Domain (dev): dev.internal.users.crowai.dev

Schema

user

ColumnTypeNotes
idtext PKInternal UUID
betterAuthUserIdtextunique, FK to auth service user
organizationIdtextInternal org UUID
emailtext
nametext
profilePictureUrltextnullable, R2 URL
onboardingIdtextnullable
permissionstextJSON (chat, interactions, patterns, teamManagement, apiKeyManagement)
statustextdefault pending, also active
roletextdefault member, also owner, admin
createdAtintegerepoch ms
updatedAtintegerepoch ms

Routes

MethodPathDescriptionAuth
POST/api/v1/usersCreate userService key
POST/api/v1/users/createCreate user directly (onboarding)Service key
GET/api/v1/users/{id}Get user by internal IDJWT
GET/api/v1/users/by-auth-id/{betterAuthUserId}Lookup by Better Auth IDService key (fail-closed)
GET/api/v1/users/meGet current user from JWTJWT
GET/api/v1/users/{id}/permissionsGet user permissionsJWT
GET/api/v1/users/by-organization/{organizationId}List users in orgJWT
GET/api/v1/users/search-email?q=Search users by email prefixJWT + org context
POST/api/v1/users/check-emailsCheck which emails exist as usersService key
PATCH/api/v1/users/{id}/profileUpdate name/profile picture URLJWT
POST/api/v1/users/{id}/profile-pictureUpload profile picture to R2JWT
POST/api/v1/users/onboardUpdate profile after signupJWT
POST/api/v1/user-buildersCreate user builder (onboarding)Service key
GET/api/v1/user-builders/{id}Get user builderService key
POST/api/v1/user-builders/{id}/finalizeFinalize builder into userService key
GET/api/v1/billing-buildersProxy to billing service buildersService key

Environment Variables

VariableExample
ENVIRONMENTdev
AUTH_SERVICE_URLhttps://dev.internal.auth-api.crowai.dev

Secrets

SecretPurpose
BETTER_AUTH_SECRETJWT verification
INTERNAL_GATEWAY_KEYGateway trust validation

Bindings

BindingTypeName
DBD1crow-core-user-service-db
R2_BUCKETR2crow-core-user-service-store (profile pictures)

Dependencies

  • Inbound: auth service (user sync, by-auth-id lookup), gateway (org resolution), org service (member listing)
  • Outbound: auth service (JWT verification)

Key Behaviors

  • INTERNAL_GATEWAY_KEY guard: All /api/v1/* routes require the X-Internal-Key header matching the shared secret
  • Service key guards: Write endpoints (/users, /users/create, /user-builders, /billing-builders, /check-emails) require X-Service-API-Key
  • by-auth-id fail-closed: Returns 401 if no auth header is present (not fail-open)
  • Permissions JSON structure: { chat: { enabled, components, lookbackWindow }, interactions, patterns, teamManagement, apiKeyManagement }