Skip to content

feat(backend): Support recent BAPI users and email/phone features#8694

Merged
brkalow merged 2 commits into
mainfrom
daniel/feat-backend-bapi-create-user-and-email-phone-put
May 29, 2026
Merged

feat(backend): Support recent BAPI users and email/phone features#8694
brkalow merged 2 commits into
mainfrom
daniel/feat-backend-bapi-create-user-and-email-phone-put

Conversation

@dmoerner
Copy link
Copy Markdown
Contributor

@dmoerner dmoerner commented May 28, 2026

Description

Add support for PUT endpoints to replace emails or phones with a new email or phone.

Add support for banned and locked param when creating a user. Since this is a tiny change I just grouped it into this PR.

Following existing patterns for these simple backend changes we don't really include tests.

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Add support for `PUT` endpoints to replace emails or phones with a new
email or phone.

Add support for `banned` and `locked` param when creating a user. Since
this is a tiny change I just grouped it into this PR.
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 28, 2026

🦋 Changeset detected

Latest commit: 73c627e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 10 packages
Name Type
@clerk/backend Minor
@clerk/astro Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/hono Patch
@clerk/nextjs Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/tanstack-react-start Patch
@clerk/testing Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link
Copy Markdown

vercel Bot commented May 28, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
clerk-js-sandbox Ready Ready Preview, Comment May 29, 2026 1:40pm

Request Review

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 28, 2026

Open in StackBlitz

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@8694

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@8694

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@8694

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@8694

@clerk/expo

npm i https://pkg.pr.new/@clerk/expo@8694

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@8694

@clerk/express

npm i https://pkg.pr.new/@clerk/express@8694

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@8694

@clerk/hono

npm i https://pkg.pr.new/@clerk/hono@8694

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@8694

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@8694

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@8694

@clerk/react

npm i https://pkg.pr.new/@clerk/react@8694

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@8694

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@8694

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@8694

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@8694

@clerk/ui

npm i https://pkg.pr.new/@clerk/ui@8694

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@8694

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@8694

commit: 73c627e

@github-actions
Copy link
Copy Markdown
Contributor

Snapi: no API changes detected in @clerk/backend, @clerk/clerk-js, @clerk/nextjs, @clerk/react, @clerk/shared, @clerk/ui.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 28, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds two independent feature enhancements: a changeset documenting UI behavior where expired email verification codes trigger automatic resend with a softer error message (replacing the previous manual resend screen), and a backend API expansion adding two new user email/phone replacement methods (replaceUserEmailAddress and replaceUserPhoneNumber) plus banned and locked parameters to user creation. The backend implementation validates user IDs and issues PUT requests to sub-resources, returning typed email/phone responses.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main changes: adding backend API support for user creation with new parameters and email/phone replacement endpoints.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The pull request description clearly relates to the changeset, explaining the addition of PUT endpoints for replacing emails/phones and support for banned/locked user creation parameters.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/backend/src/api/endpoints/UserApi.ts (1)

104-107: ⚡ Quick win

Please add tests for the new user replacement endpoints and creation flags.

This PR introduces new API behaviors (replaceUserEmailAddress, replaceUserPhoneNumber, and createUser banned/locked flags) but no test updates are included.

As per coding guidelines, "**/*: If there are no tests added or modified as part of the PR, please suggest that tests be added to cover the changes."

Also applies to: 278-296

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/backend/src/api/endpoints/UserApi.ts` around lines 104 - 107, Add
unit/integration tests covering the new user replacement endpoints and creation
flags: write tests for replaceUserEmailAddress and replaceUserPhoneNumber
ensuring success, validation errors, and authorization cases are handled; add
tests for createUser that assert banned and locked flags set the created user's
state correctly (cannot sign in when banned, locked behavior per feature flag)
and include negative cases when feature support is missing; use existing test
helpers and the same test suites that exercise user creation and update flows so
the new endpoints and fields are covered by CI.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/backend/src/api/endpoints/UserApi.ts`:
- Around line 278-296: Update the public method signatures in UserApi so they
explicitly declare Promise return types: change replaceUserEmailAddress(userId:
string, params: ReplaceUserEmailAddressParams) to
replaceUserEmailAddress(userId: string, params: ReplaceUserEmailAddressParams):
Promise<EmailAddress> and replaceUserPhoneNumber(userId: string, params:
ReplaceUserPhoneNumberParams): Promise<PhoneNumber>; keep the existing
this.request calls but ensure the declared return types match the generic types
passed to this.request, and add unit/integration tests that call
UserApi.replaceUserEmailAddress and UserApi.replaceUserPhoneNumber to verify
request shape and response handling for the new endpoints.

---

Nitpick comments:
In `@packages/backend/src/api/endpoints/UserApi.ts`:
- Around line 104-107: Add unit/integration tests covering the new user
replacement endpoints and creation flags: write tests for
replaceUserEmailAddress and replaceUserPhoneNumber ensuring success, validation
errors, and authorization cases are handled; add tests for createUser that
assert banned and locked flags set the created user's state correctly (cannot
sign in when banned, locked behavior per feature flag) and include negative
cases when feature support is missing; use existing test helpers and the same
test suites that exercise user creation and update flows so the new endpoints
and fields are covered by CI.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 8882943f-1951-412c-bfc8-a3e108dc2926

📥 Commits

Reviewing files that changed from the base of the PR and between 37535f9 and bdbdaa1.

📒 Files selected for processing (3)
  • .changeset/auto-resend-expired-email-verification.md
  • .changeset/backend-user-replace-email-phone-and-banned-locked.md
  • packages/backend/src/api/endpoints/UserApi.ts

Comment on lines +278 to +296
public async replaceUserEmailAddress(userId: string, params: ReplaceUserEmailAddressParams) {
this.requireId(userId);

return this.request<EmailAddress>({
method: 'PUT',
path: joinPaths(basePath, userId, 'email_address'),
bodyParams: params,
});
}

public async replaceUserPhoneNumber(userId: string, params: ReplaceUserPhoneNumberParams) {
this.requireId(userId);

return this.request<PhoneNumber>({
method: 'PUT',
path: joinPaths(basePath, userId, 'phone_number'),
bodyParams: params,
});
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify public async methods without explicit return types in UserApi.ts
rg -nP "public async [A-Za-z0-9_]+\([^)]*\)\s*\{" packages/backend/src/api/endpoints/UserApi.ts

Repository: clerk/javascript

Length of output: 1919


Add explicit Promise return types for new UserApi public methods

replaceUserEmailAddress and replaceUserPhoneNumber should declare : Promise<EmailAddress> / : Promise<PhoneNumber> for a stable public surface.

Proposed fix
-  public async replaceUserEmailAddress(userId: string, params: ReplaceUserEmailAddressParams) {
+  public async replaceUserEmailAddress(
+    userId: string,
+    params: ReplaceUserEmailAddressParams,
+  ): Promise<EmailAddress> {
     this.requireId(userId);

     return this.request<EmailAddress>({
       method: 'PUT',
       path: joinPaths(basePath, userId, 'email_address'),
       bodyParams: params,
     });
   }

-  public async replaceUserPhoneNumber(userId: string, params: ReplaceUserPhoneNumberParams) {
+  public async replaceUserPhoneNumber(
+    userId: string,
+    params: ReplaceUserPhoneNumberParams,
+  ): Promise<PhoneNumber> {
     this.requireId(userId);

     return this.request<PhoneNumber>({
       method: 'PUT',
       path: joinPaths(basePath, userId, 'phone_number'),
       bodyParams: params,
     });
   }

Add tests covering these newly introduced API methods/endpoints.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/backend/src/api/endpoints/UserApi.ts` around lines 278 - 296, Update
the public method signatures in UserApi so they explicitly declare Promise
return types: change replaceUserEmailAddress(userId: string, params:
ReplaceUserEmailAddressParams) to replaceUserEmailAddress(userId: string,
params: ReplaceUserEmailAddressParams): Promise<EmailAddress> and
replaceUserPhoneNumber(userId: string, params: ReplaceUserPhoneNumberParams):
Promise<PhoneNumber>; keep the existing this.request calls but ensure the
declared return types match the generic types passed to this.request, and add
unit/integration tests that call UserApi.replaceUserEmailAddress and
UserApi.replaceUserPhoneNumber to verify request shape and response handling for
the new endpoints.

Copy link
Copy Markdown
Member

@wobsoriano wobsoriano left a comment

Choose a reason for hiding this comment

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

looks good, small request!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🪓

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oops, removed!

@brkalow brkalow merged commit 1701e0f into main May 29, 2026
45 checks passed
@brkalow brkalow deleted the daniel/feat-backend-bapi-create-user-and-email-phone-put branch May 29, 2026 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants