tsrpc-template icon indicating copy to clipboard operation
tsrpc-template copied to clipboard

权限问题

Open hildxd opened this issue 3 years ago • 1 comments

当user.roles为空数组的时候 我给Ptl 增加auths: { roles: ["1"] } 不会触发校验是正常的吗 image

hildxd avatar Jan 11 '23 08:01 hildxd

如果用户的roles为空 就算协议文件定义了roles也能让用户请求成功 改成这样会不会好一点

        const userRoles = node.userRoles ?? [];
        if (type === "SOME") {
          const hasRole = roles.some((role) => userRoles.includes(role));
          if (!hasRole) {
            await node.error(
              new TsrpcError({
                message: "您没有权限操作。",
                code: "NOT_PERMISSION",
                type: TsrpcErrorType.ApiError,
              })
            );
          }
        } else if (type === "EVERY") {
          const mustRole = roles.every((role) => userRoles.includes(role));
          if (!mustRole) {
            await node.error(
              new TsrpcError({
                message: "您没有权限执行此操作。",
                code: "NOT_PERMISSION",
                type: TsrpcErrorType.ApiError,
              })
            );
          }
        }

hildxd avatar Jan 11 '23 08:01 hildxd