Skip to main content
ArcBlock Community

Custom Components in Discuss Kit

Twelve
Developers
discuss-kitfeaturequalifiedresolvedrewarded

Hello team.

Are we able to lock the custom components away from public use?

I want to make components and only give acess

4.jpg

to select people in the discuss kit. As it is right now, once the component is made anybody can use a command to open it in discuss kit. I want to make some of them private. Is this possible?

7 replies

wangqi15 months ago

This is not currently possible. We will consider adding a feature to control the access to the components in the future, but don't have an ideal solution at the moment. Further discussion is needed to determine the best approach, and we'll keep you updated.

For now, it’s only possible to make components display different content for different users. If this meets your needs, you can refer to the following code:

javascriptCopy
import React from '@blocklet/pages-kit/builtin/react';
import { Box } from '@blocklet/pages-kit/builtin/mui/material';
import { useSessionContext } from '@blocklet/pages-kit/builtin/session';
export default function () {
  const ctx = useSessionContext();
  const isAuthenticated = !!ctx?.session?.user;
  const passport = ctx?.session?.user?.role; // Note: 'role' is often referred to as 'passport' in blocklet apps
  if (!isAuthenticated) {
    return (
      <Box>
        This content is intended for unauthenticated users. You can also return null to make this component completely invisible to them.
      </Box>
    );
  }
  
  if (passport === 'admin') {
    return (
      <Box>
        This content is meant for admin users.
      </Box>
    );
  }
  return (
    <Box>
      This content is for all authenticated users who do not have admin privileges.
    </Box>
  );
}
Twelve15 months ago

Thank you! This actually works well for our current need. One other feature that you may want to consider is adding text such as “You don’t have correct permission to view this component” when someone tries to open a component they don’t have permission to view. Right now a blank screen appears and it is not clear what is happening.

xiaoliang15 months ago

访问没有权限的组件,具体是指什么呢?因为现在组件是没有权限控制的 是指没有权限的用户访问 Draft Preview 链接吗?

Twelve15 months ago

When using the discuss kit, any user can use the component picker. If a user picks a component without having the neccessary passport, then in the text box where the component usually shows up, a blank space appears. The user knows this because a gear icon appears in the dialogue box.

This can be confusing to users and they may think the component is broken if they are not given any further information.

wangqi15 months ago

We discussed this issue and are considering restricting components usage to admin users only. This would ensure users cannot add components without the required admin/owner permissions. Suggestions are welcome.

Twelve15 months ago

if only admins had acess to component picker, that would be a plus, but also keeping the passport system in place would be great.

I have a comic website. I’ve built a component that allows for digital vie of the comics. I can load these components Up onto a blog and then gate that with a custom passport. I can then sell the passports needed to view these blogs, essentially creating a paywall for our comics. That’s why this current setup works so well.

wangqi15 months ago

We’ve just released an update to DiscussKit that lets you control access to components based on passports. You can set it up by going to:

Server Dashboard → DiscussKit Preferences → Pages Kit Component Access Control → Allowed Passports

image.png

image.png

Only users with the specified passports will be able to access and use those components in the post editor.

The supported built-in passport values are: admin, owner, member, and guest.

If you’re using custom passports, you can find their identifiers under Manage Passports.

image.png

Let us know if you run into any issues.

Reply