SSE Hooks

useRoleGuard

GitHub
Custom hook for Role-Based Access Control (RBAC). Checks if a user has specific permissions and handles redirection for unauthorized access.

Installation

npx sse-hooks add use-role-guard

Usage

example.ts
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

Prop Default Type
options

{}

UseRoleGuardOptions

Configuration options including user object and redirect paths.

requiredRoles-

string[]

The list of roles required to access the resource.

Returns

Return Value Default Type
return-

UseRoleGuardReturn

Hook return value

Types Aliases

No specific type aliases defined for this component.

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