Skip to content

The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.

485 B
Raw Blame
import { useContext } from "react"
import { PermissionsContext } from "./permissions-context"

/**
 * @example
 * ```tsx
 * const { can, hasPermission } = usePermissions()
 *
 * if (can("customers", "edit")) { ... }
 * if (hasPermission("customers:view")) { ... }
 * ```
 */
export const usePermissions = () => {
  const context = useContext(PermissionsContext)

  if (!context) {
    throw new Error("usePermissions must be used within a PermissionsProvider")
  }

  return context
}