Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

权限问题 #1

Open
hildxd opened this issue Jan 11, 2023 · 1 comment
Open

权限问题 #1

hildxd opened this issue Jan 11, 2023 · 1 comment

Comments

@hildxd
Copy link

hildxd commented Jan 11, 2023

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

@hildxd
Copy link
Author

hildxd commented Jan 11, 2023

如果用户的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,
              })
            );
          }
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant