feat(backend): Support recent BAPI users and email/phone features#8694
Conversation
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 detectedLatest commit: 73c627e The changes in this PR will be included in the next version bump. This PR includes changesets to release 10 packages
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 |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/hono
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/react
@clerk/react-router
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/ui
@clerk/upgrade
@clerk/vue
commit: |
|
Snapi: no API changes detected in |
📝 WalkthroughWalkthroughThis 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 ( Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/backend/src/api/endpoints/UserApi.ts (1)
104-107: ⚡ Quick winPlease add tests for the new user replacement endpoints and creation flags.
This PR introduces new API behaviors (
replaceUserEmailAddress,replaceUserPhoneNumber, andcreateUserbanned/lockedflags) 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
📒 Files selected for processing (3)
.changeset/auto-resend-expired-email-verification.md.changeset/backend-user-replace-email-phone-and-banned-locked.mdpackages/backend/src/api/endpoints/UserApi.ts
| 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, | ||
| }); | ||
| } |
There was a problem hiding this comment.
🧩 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.tsRepository: 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.
wobsoriano
left a comment
There was a problem hiding this comment.
looks good, small request!
Description
Add support for
PUTendpoints to replace emails or phones with a new email or phone.Add support for
bannedandlockedparam 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 testruns as expected.pnpm buildruns as expected.Type of change