diff --git a/packages/core/src/routes/admin-user.ts b/packages/core/src/routes/admin-user.ts index 86af33887..1fbddbd98 100644 --- a/packages/core/src/routes/admin-user.ts +++ b/packages/core/src/routes/admin-user.ts @@ -1,4 +1,4 @@ -import { userInfoSelectFields } from '@logto/schemas'; +import { customDataGuard, userInfoSelectFields } from '@logto/schemas'; import pick from 'lodash.pick'; import { InvalidInputError } from 'slonik'; import { object, string } from 'zod'; @@ -126,4 +126,28 @@ export default function adminUserRoutes(router: T) { return next(); } ); + + router.patch( + '/users/:userId/custom-data', + koaGuard({ + params: object({ userId: string().min(1) }), + body: object({ customData: customDataGuard }), + }), + async (ctx, next) => { + const { + params: { userId }, + body: { customData }, + } = ctx.guard; + + await findUserById(userId); + + const user = await updateUserById(userId, { + customData, + }); + + ctx.body = pick(user, ...userInfoSelectFields); + + return next(); + } + ); } diff --git a/packages/schemas/src/types/user.ts b/packages/schemas/src/types/user.ts index 6cee5b717..dc755f593 100644 --- a/packages/schemas/src/types/user.ts +++ b/packages/schemas/src/types/user.ts @@ -6,6 +6,7 @@ export const userInfoSelectFields = Object.freeze([ 'primaryEmail', 'primaryPhone', 'roleNames', + 'customData', ] as const); export type UserInfo = Pick<