Skip to content

feat(api): create users via referring integrations#2463

Merged
nickscamara merged 6 commits intomainfrom
mog/user-referring-integration
Dec 2, 2025
Merged

feat(api): create users via referring integrations#2463
nickscamara merged 6 commits intomainfrom
mog/user-referring-integration

Conversation

@mogery
Copy link
Copy Markdown
Member

@mogery mogery commented Dec 1, 2025

Summary by cubic

Adds a new admin endpoint to create users via referring integrations, issue API keys, and apply integration-specific coupons. This enables partners to onboard users programmatically with a simple API.

  • New Features
    • POST /admin/create-user: accepts email and authenticates via Bearer token (SHA-256 matched against user_referring_integration.key).
    • If the user exists under a different referrer, reuse or create a team for the current referrer and return its API key.
    • If new, create the user with referrer metadata, get the team’s API key, and return it.
    • Applies integration-defined coupons (credits, code, optional expiry in ms offset, rate limit/concurrency overrides).
    • Response: { apiKey, alreadyExisted }. Errors return clear 4xx/5xx messages.

Written for commit a3e140e. Summary will update automatically on new commits.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files

Prompt for AI agents (all 1 issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="apps/api/src/controllers/v0/admin/create-user.ts">

<violation number="1" location="apps/api/src/controllers/v0/admin/create-user.ts:69">
P2: Validate that a Bearer token value is present before hashing it; otherwise requests with an empty token crash the controller and return 500 instead of 401.</violation>
</file>

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR

Comment thread apps/api/src/controllers/v0/admin/create-user.ts
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 2 files

Prompt for AI agents (all 2 issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="apps/api/src/controllers/v0/admin/create-user.ts">

<violation number="1" location="apps/api/src/controllers/v0/admin/create-user.ts:50">
P2: Malformed Bearer headers (`Authorization: Bearer` with no token) crash the handler and return 500 instead of a 401 because `token` is hashed without being validated.</violation>

<violation number="2" location="apps/api/src/controllers/v0/admin/create-user.ts:170">
P1: New teams created for preexisting users are never added to `user_teams`, so the user isn’t associated with the team and subsequent requests keep creating duplicate teams/coupons.</violation>
</file>

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR

Comment thread apps/api/src/controllers/v0/admin/create-user.ts
Comment thread apps/api/src/controllers/v0/admin/create-user.ts
mogery and others added 2 commits December 2, 2025 08:28
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
@mogery
Copy link
Copy Markdown
Member Author

mogery commented Dec 2, 2025

@cubic-dev-ai please re-review

@cubic-dev-ai
Copy link
Copy Markdown
Contributor

cubic-dev-ai Bot commented Dec 2, 2025

@cubic-dev-ai please re-review

@mogery I've started the AI code review. It'll take a few minutes to complete.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files

Prompt for AI agents (all 1 issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="apps/api/src/controllers/v0/admin/create-user.ts">

<violation number="1" location="apps/api/src/controllers/v0/admin/create-user.ts:96">
P2: `alreadyExisted` stays false when an existing user needs a new team for this referrer, causing an incorrect API response. Set the flag as soon as a preexisting user is detected.</violation>
</file>

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR

Comment thread apps/api/src/controllers/v0/admin/create-user.ts
@nickscamara nickscamara merged commit 19a7b9a into main Dec 2, 2025
7 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants