feat(core, schemas): list user grants by userId#8482
Open
feat(core, schemas): list user grants by userId#8482
Conversation
COMPARE TO
|
| Name | Diff |
|---|---|
| packages/core/src/mocks/oidc-grant.ts | 📈 +420 Bytes |
| packages/core/src/libraries/session.ts | 📈 +915 Bytes |
| packages/core/src/queries/oidc-model-instance.test.ts | 📈 +3.13 KB |
| packages/core/src/queries/oidc-model-instance.ts | 📈 +2.07 KB |
| packages/core/src/routes/admin-user/session.openapi.json | 📈 +856 Bytes |
| packages/core/src/routes/admin-user/session.ts | 📈 +794 Bytes |
| packages/integration-tests/src/api/admin-user.ts | 📈 +356 Bytes |
| packages/integration-tests/src/tests/api/sessions/index.test.ts | 📈 +1.97 KB |
| packages/schemas/alterations/next-1772621060-add-oidc-model-instances-grant-account-id-index.ts | 📈 +902 Bytes |
| packages/schemas/src/types/user-sessions.ts | 📈 +779 Bytes |
| packages/schemas/tables/oidc_model_instances.sql | 📈 +177 Bytes |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a management (dev-feature) API to list a user’s active OIDC application grants, with optional filtering by first-party vs third-party applications, and improves query performance via a dedicated index.
Changes:
- Add
GET /users/:userId/grants(and OpenAPI doc) returning non-expired grants with optionalappTypefilter. - Add DB index for Grant lookups by
(payload->>'accountId')+expires_at(including an alteration script for concurrent creation). - Add schema guards/types and integration/unit test coverage for the new query/endpoint.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/schemas/tables/oidc_model_instances.sql | Adds a baseline schema index for Grant lookups by accountId/expiry. |
| packages/schemas/alterations/next-1772621060-add-oidc-model-instances-grant-account-id-index.ts | Adds concurrent migration to create/drop the new index safely in existing DBs. |
| packages/schemas/src/types/user-sessions.ts | Introduces Zod guards/types for “user application grant” API responses. |
| packages/core/src/queries/oidc-model-instance.ts | Adds query to fetch active Grant instances joined to Applications (supports appType filtering). |
| packages/core/src/queries/oidc-model-instance.test.ts | Adds unit tests asserting SQL generation and parameters for the new query. |
| packages/core/src/libraries/session.ts | Adds formatting/validation and library method to expose active grants to routes. |
| packages/core/src/routes/admin-user/session.ts | Adds the new admin-user grants route with request/response guards. |
| packages/core/src/routes/admin-user/session.openapi.json | Documents the new endpoint and its appType query parameter. |
| packages/integration-tests/src/api/admin-user.ts | Adds an integration-test API client helper for GET /users/:userId/grants. |
| packages/integration-tests/src/tests/api/sessions/index.test.ts | Adds an integration test validating grant retrieval and appType filtering. |
| packages/core/src/mocks/oidc-grant.ts | Adds a test helper to mock Grant instances in query unit tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| export type QueryResult = Pick<OidcModelInstance, 'payload' | 'consumedAt'>; | ||
|
|
||
| const { table, fields } = convertToIdentifiers(OidcModelInstances); | ||
| const { table: applicationTable, fields: applicationFields } = convertToIdentifiers(Applications); |
packages/schemas/alterations/next-1772621060-add-oidc-model-instances-grant-account-id-index.ts
Outdated
Show resolved
Hide resolved
wangsijie
approved these changes
Mar 16, 2026
d1a7305 to
c4d7590
Compare
list user grants by userId
add dev feature guard
add dev feature guard
remove unused code
c90f242 to
adfa59c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Introduce a new
GET /users/:userId/grantsendpoint to support listing user grants by userId. With an optional filter parameterappType, allow filtering the grants by application type.Testing
Integration tests added.
Checklist
.changeset