usePermissions
Permission string list.
Import
TypeScript
import { usePermissions } from '@/hooks';API
Signature
usePermissions() → string[]
When to use
Use usePermissions instead of re-implementing the same pattern in multiple components.
SSR / Next.js
Provider can wrap client layouts; seed isLoading during session hydrate.
Live playground
Edit the example and see it run against the real @/hooks package in this app.
Live playgroundEdit · run with real
@/hooks · usePermissionsEditor
function Perms() { const permissions = usePermissions(); return <pre>{permissions.join(', ')}</pre>; }
Preview
Implementation source
Full library source for usePermissions — copy into your project when you are not installing a package yet.
hooks/auth/usePermissions.ts
import { useAuth } from './useAuth';
/** Permission list for the current user. */
export function usePermissions(): string[] {
return useAuth().permissions;
}
Copy-paste example
usePermissions.example.tsx
'use client';
import { usePermissions } from '@/hooks';
export function Perms() {
const permissions = usePermissions();
return <pre>{permissions.join(', ')}</pre>;
}Production checklist
- Called only from Client Components or other custom hooks
- Type parameters filled in (e.g.
useFetch<User[]>) - Tip: Wrap the tree with AuthProvider and pass your session shape — keep it generic.
- Source of truth: open
hooks/auth/usePermissions.tsfor implementation details