Skip to content

feat(core): support searching users by custom data - #9793

Merged
wangsijie merged 6 commits into
masterfrom
wangsijie-8550-search-users-by-custom-data
Oct 22, 2026
Merged

wangsijie merged 6 commits into
masterfrom
wangsijie-8550-search-users-by-custom-data

Conversation

@wangsijie

@wangsijie wangsijie commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #8550.

Add a repeatable customData query parameter to GET /api/users for exact user lookup by user custom data.

Each value is a JSON object and is matched with users.custom_data @> value::jsonb. Matching is type-strict, supports nested objects and arrays, treats null as an explicit value, and rejects empty objects/arrays. Keys within one object are ANDed, repeated customData parameters are ORed, and the filter is combined with existing user filters using AND. Raw JSON text is passed to PostgreSQL to preserve large integers.

Also updates the OpenAPI definition and adds unit/integration coverage.

Custom data filtering is not backed by a GIN index: PostgreSQL row-level security prevents the non-leakproof JSONB containment operator from using one. Combine customData with other selective filters for large user sets. Docs: logto-io/docs#1520.

Testing

Tested locally

Checklist

  • .changeset
  • unit tests
  • integration tests
  • necessary TSDoc comments

Add a repeatable `customData` query parameter to `GET /api/users` that
matches `users.custom_data` with JSONB containment (`@>`). Values within
one object are combined with AND, repeated parameters with OR, and other
user filters with AND. The feature is guarded by `isDevFeaturesEnabled`.

Add a GIN index for custom data containment lookups and document the new
parameter in OpenAPI.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1570d-dbc7-707d-9f3d-cdda9406fd02
Remove the dev feature gate so the repeatable `customData` filter on
`GET /api/users` is available by default, and add a changeset for the new
Management API capability.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1570d-dbc7-707d-9f3d-cdda9406fd02
Copilot AI balanced review requested due to automatic review settings October 20, 2026 03:04

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI balanced review requested due to automatic review settings October 20, 2026 03:22

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added size/l and removed size/l labels Oct 20, 2026
Comment thread packages/schemas/tables/users.sql Outdated
Comment thread packages/schemas/alterations/next-1792462000-add-users-custom-data-gin-index.ts Outdated
Comment thread packages/core/src/routes/admin-user/search.ts
Comment thread packages/core/src/routes/admin-user/search.ts
PostgreSQL row-level security prevents non-leakproof JSONB containment
from using a GIN index, so the users_custom_data_gin index did not help
tenant-scoped queries. Remove the index and its alteration; custom data
lookups should be combined with other selective filters.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1570d-dbc7-707d-9f3d-cdda9406fd02
Copilot AI balanced review requested due to automatic review settings October 20, 2026 04:12

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added size/l and removed size/l labels Oct 20, 2026
Limit repeated `customData` query values to 20 so a single request cannot add an
unbounded number of JSONB containment checks to every scanned user row.

Map PostgreSQL error codes `22P05` (unsupported Unicode escape sequence) and
`22003` (numeric overflow) to `request.invalid_input`, since raw JSON text
that passes `JSON.parse` can still be rejected by the JSONB cast.
Copilot AI balanced review requested due to automatic review settings October 20, 2026 12:01

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot removed the size/l label Oct 20, 2026
Comment thread .changeset/legal-islands-move.md Outdated
Comment thread packages/core/src/routes/admin-user/search.openapi.json Outdated
Replace `qq` with `customId` in the OpenAPI description, examples, and the
parameter hint, and simplify the changeset summary.
Copilot AI balanced review requested due to automatic review settings October 22, 2026 01:33

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added size/xl and removed size/l labels Oct 22, 2026
@wangsijie
wangsijie merged commit 7945f99 into master Oct 22, 2026
34 checks passed
@wangsijie
wangsijie deleted the wangsijie-8550-search-users-by-custom-data branch October 22, 2026 02:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

feature request: support search by custom data

4 participants