MCPcopy Create free account
hub / github.com/coderwhy/coderhub / verifyPermission

Function verifyPermission

src/middleware/auth.middleware.js:68–86  ·  view source on GitHub ↗
(ctx, next)

Source from the content-addressed store, hash-verified

66 * 多对多: role -> menu(删除动态/修改动态)
67 */
68const verifyPermission = async (ctx, next) => {
69 console.log("验证权限的middleware~");
70
71 // 1.获取参数 { commentId: '1' }
72 const [resourceKey] = Object.keys(ctx.params);
73 const tableName = resourceKey.replace('Id', '');
74 const resourceId = ctx.params[resourceKey];
75 const { id } = ctx.user;
76
77 // 2.查询是否具备权限
78 try {
79 const isPermission = await authService.checkResource(tableName, resourceId, id);
80 if (!isPermission) throw new Error();
81 await next();
82 } catch (err) {
83 const error = new Error(errorTypes.UNPERMISSION);
84 return ctx.app.emit('error', error, ctx);
85 }
86}
87
88// const verifyPermission = (tableName) => {
89// return async (ctx, next) => {

Callers

nothing calls this directly

Calls 1

checkResourceMethod · 0.80

Tested by

no test coverage detected