SSE Hooks

useRoleGuard

Custom hook for Role-Based Access Control (RBAC).

Installation

npx sse-tool add use-role-guard

Usage

import { useRoleGuard } from "./{hooks file}";

const { hasAccess, user, isLoading } = useRoleGuard(["admin", "editor"], {
  redirectTo: "/login",
});
if (isLoading) return <Loader />;
if (!hasAccess) return null; // Will redirect automatically
return <AdminPanel user={user} />;

API

Parameters

NameTypeDescription
requiredRolesstring[]The list of roles required to access the resource.
optionsUseRoleGuardOptionsConfiguration options including user object and redirect paths.

Return Value

Returns UseRoleGuardReturn.

Access status, user data, and role checking utilities.

Changelog

31af5 — Refactor useBattery hook and remove utility functions

c165d — feat: enhance useRoleGuard and useSSR hooks with additional options and documentation

30da4 — feat: add new hooks and their metadata

2f161 — feat: add useConferenceSystem, useKbd, useMediaQuality, useNetworkInformation, usePortal, useRoleGuard, useScreenShare, useSymbol hooks

Built with Love • © 2026