Components authentication

RoleGate

Conditional rendering component that shows or hides content based on user roles. It supports OR logic (any role matches) or AND logic (all roles must match). Use it for role‑specific UI elements such as admin buttons or owner‑only sections.

已更新 Mar 6, 2026

RoleGate

Conditional rendering component that shows or hides content based on user roles. It supports OR logic (any role matches) or AND logic (all roles must match). Use it for role‑specific UI elements such as admin buttons or owner‑only sections.

Use Cases

  • Show admin‑only buttons to users with ‘owner’ or ‘admin’ role
  • Display editor tools only to users with ‘editor’ role
  • Hide sensitive actions from non‑owners
  • Create role‑specific UI sections

Properties

allowedRoles

List of role names that can view the content. User needs ANY role (OR logic) or ALL roles (AND logic) depending on requireAllRoles setting. Type: array.

Tip: System roles – use ‘owner’ for app creator, ‘authenticated’ for any logged‑in user.
Custom roles – use names like ‘editor’, ‘viewer’, ‘manager’ as needed.
OR logic – default behavior; user needs ANY of these roles (most common).

requireAllRoles

If true, user must have ALL roles in allowedRoles. If false (default), user needs ANY role (OR logic). Type: boolean. Default: false.

Tip: Use false (default) for most cases – user needs ANY role.
Use true only when the user must possess multiple specific roles simultaneously.

showLoginPrompt

If true, shows a login prompt to unauthenticated users. If false, shows nothing. Type: boolean. Default: true.

Tip: Use true (default) to guide users to log in.
Use false when content should silently disappear for unauthorized users.

items

Array of Puck components to conditionally render based on roles. Each item is a full component object with type and props. Type: array.

Best Practices

  • Use OR logic (requireAllRoles: false) by default – user needs ANY of the allowed roles
  • Use AND logic (requireAllRoles: true) only when user must have ALL specified roles
  • Set showLoginPrompt: true to guide unauthenticated users
  • Wrap buttons, sections, or entire components in RoleGate
  • Use items array to nest multiple components

Common Mistakes

Using requireAllRoles: true when OR logic is intended

Why it's a problem: User must have ALL roles (admin AND editor) instead of ANY role. Most cases need OR logic.

Fix: Use requireAllRoles: false (default) for OR logic – user needs ANY allowed role.

Empty allowedRoles array

Why it's a problem: No roles allowed means content never shows, even to owner.

Fix: Specify at least one role in allowedRoles (e.g., ['owner']).

Using items as simple objects instead of Puck components

Why it's a problem: Items must be full component objects with type and props.

Fix: Use format: [{type: 'Button', props: {...}}] not just [{label: 'Click'}].

标签

rolegate authentication show admin-only display editor hide sensitive

相关组件

准备好构建了吗?

使用 Qödiak 免费开始创建您的应用。

免费开始

相关文章

AnimatedGradient

Smooth animated gradient background for modern, premium aesthetics. Supports linear and radial gradients with configurable colors, animation speed, and intensity. GPU‑accelerated for smooth 60fps performance.

Button

Interactive button component that supports link navigation, page data source operations (record navigation, new record, mode switching), form submission, and custom JavaScript execution. Save/Delete actions must use a custom‑script with navigation. Two visual variants are available, and the button can be enabled or disabled dynamically based on data context.

Calendar

A full‑featured calendar component built with react‑big‑calendar. It can display events in month, week, day, or agenda views and includes navigation and view‑switching capabilities, making it suitable for any site that needs scheduling, event management, or date visualization.

Card

Feature card component with an icon, title, description, and entrance animations. Ideal for showcasing features, services, or benefits in grid layouts with animation support.

Checkbox

A checkbox group component that lets users select multiple options from a predefined list. It renders a set of checkboxes with individual labels and can be arranged vertically or horizontally.

CountdownTimer

Real-time countdown timer component that displays the time remaining until a target date/time. It updates every second, offers customizable formatting, and shows a completion message when the countdown ends. Suitable for any site type.