Skip to content

Commit

Permalink
User ID Search, Again (#414)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCactusBlue authored Jan 31, 2025
1 parent d6ece57 commit e27f774
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion apps/backend/src/app/api/v1/users/crud.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { hashPassword, isPasswordHashValid } from "@stackframe/stack-shared/dist
import { deepPlainEquals } from "@stackframe/stack-shared/dist/utils/objects";
import { createLazyProxy } from "@stackframe/stack-shared/dist/utils/proxies";
import { typedToLowercase } from "@stackframe/stack-shared/dist/utils/strings";
import { isUuid } from "@stackframe/stack-shared/dist/utils/uuids";
import { teamPrismaToCrud, teamsCrudHandlers } from "../teams/crud";

export const userFullInclude = {
Expand Down Expand Up @@ -444,7 +445,7 @@ export const usersCrudHandlers = createLazyProxy(() => createCrudHandlers(usersC
cursor: yupString().uuid().optional().meta({ openapiField: { onlyShowInOperations: [ 'List' ], description: "The cursor to start the result set from." } }),
order_by: yupString().oneOf(['signed_up_at']).optional().meta({ openapiField: { onlyShowInOperations: [ 'List' ], description: "The field to sort the results by. Defaults to signed_up_at" } }),
desc: yupBoolean().optional().meta({ openapiField: { onlyShowInOperations: [ 'List' ], description: "Whether to sort the results in descending order. Defaults to false" } }),
query: yupString().optional().meta({ openapiField: { onlyShowInOperations: [ 'List' ], description: "A search query to filter the results by. This is a free-text search that is applied to the user's display name and primary email." } }),
query: yupString().optional().meta({ openapiField: { onlyShowInOperations: [ 'List' ], description: "A search query to filter the results by. This is a free-text search that is applied to the user's id (exact-match only), display name and primary email." } }),
}),
onRead: async ({ auth, params }) => {
const user = await getUser({ projectId: auth.project.id, userId: params.user_id });
Expand All @@ -465,6 +466,9 @@ export const usersCrudHandlers = createLazyProxy(() => createCrudHandlers(usersC
} : {},
...query.query ? {
OR: [
...(isUuid(query.query) ? [{
equals: query.query
}] : []),
{
displayName: {
contains: query.query,
Expand Down
2 changes: 2 additions & 0 deletions packages/stack-shared/src/utils/uuids.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ export function generateUuid() {
export function isUuid(str: string) {
return /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(str);
}

export const ZERO_UUID = "00000000-0000-0000-0000-000000000000" as const;

0 comments on commit e27f774

Please sign in to comment.