mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
refactor(core): remove user route (#254)
This commit is contained in:
parent
46d1fee353
commit
5731d7389d
2 changed files with 0 additions and 71 deletions
|
@ -12,7 +12,6 @@ import settingRoutes from '@/routes/setting';
|
|||
import signInExperiencesRoutes from '@/routes/sign-in-experience';
|
||||
import statusRoutes from '@/routes/status';
|
||||
import swaggerRoutes from '@/routes/swagger';
|
||||
import userRoutes from '@/routes/user';
|
||||
|
||||
import adminUserRoutes from './admin-user';
|
||||
import roleRoutes from './role';
|
||||
|
@ -23,7 +22,6 @@ const createRouters = (provider: Provider) => {
|
|||
|
||||
statusRoutes(anonymousRouter);
|
||||
sessionRoutes(anonymousRouter, provider);
|
||||
userRoutes(anonymousRouter);
|
||||
swaggerRoutes(anonymousRouter);
|
||||
|
||||
const router: AuthedRouter = new Router();
|
||||
|
|
|
@ -1,69 +0,0 @@
|
|||
import { userInfoSelectFields } from '@logto/schemas';
|
||||
import pick from 'lodash.pick';
|
||||
import { object, string } from 'zod';
|
||||
|
||||
import { encryptUserPassword } from '@/lib/user';
|
||||
import koaGuard from '@/middleware/koa-guard';
|
||||
import { deleteUserById, findUserById, updateUserById } from '@/queries/user';
|
||||
|
||||
import { AnonymousRouter } from './types';
|
||||
|
||||
export default function userRoutes<T extends AnonymousRouter>(router: T) {
|
||||
router.get(
|
||||
'/user/:userId',
|
||||
koaGuard({
|
||||
params: object({ userId: string().min(1) }),
|
||||
}),
|
||||
async (ctx, next) => {
|
||||
const {
|
||||
params: { userId },
|
||||
} = ctx.guard;
|
||||
const user = await findUserById(userId);
|
||||
ctx.body = pick(user, ...userInfoSelectFields);
|
||||
|
||||
return next();
|
||||
}
|
||||
);
|
||||
|
||||
router.patch(
|
||||
'/user/:userId/password',
|
||||
koaGuard({
|
||||
params: object({ userId: string().min(1) }),
|
||||
body: object({ password: string().min(6) }),
|
||||
}),
|
||||
async (ctx, next) => {
|
||||
const {
|
||||
params: { userId },
|
||||
body: { password },
|
||||
} = ctx.guard;
|
||||
|
||||
await findUserById(userId);
|
||||
|
||||
const { passwordEncrypted, passwordEncryptionSalt } = encryptUserPassword(userId, password);
|
||||
|
||||
const user = await updateUserById(userId, {
|
||||
passwordEncryptionSalt,
|
||||
passwordEncrypted,
|
||||
});
|
||||
ctx.body = pick(user, ...userInfoSelectFields);
|
||||
|
||||
return next();
|
||||
}
|
||||
);
|
||||
|
||||
router.delete(
|
||||
'/user/:userId',
|
||||
koaGuard({
|
||||
params: object({ userId: string().min(1) }),
|
||||
}),
|
||||
async (ctx, next) => {
|
||||
const {
|
||||
params: { userId },
|
||||
} = ctx.guard;
|
||||
await deleteUserById(userId);
|
||||
ctx.status = 204;
|
||||
|
||||
return next();
|
||||
}
|
||||
);
|
||||
}
|
Loading…
Reference in a new issue