useAuthGuard
Programmatic route protection that reports whether access is allowed and where to redirect.
import { useAuthGuard } from 'flowstack-sdk'Programmatic route protection. Pass requirements (requireAuth, requireWorkspace, redirectTo) and read back whether the current user is allowed and, if not, where to send them.
Signature
const { isAllowed, isLoading, shouldRedirect, redirectTo } = useAuthGuard(options)Parameters
| Param | Type | Notes | Description |
|---|---|---|---|
options.requireAuth | boolean | — | Require an authenticated session. |
options.requireWorkspace | boolean | — | Require a selected workspace. |
options.redirectTo | string | — | Path to redirect to when access is denied, e.g. '/login'. |
Returns
| Field | Type | Description |
|---|---|---|
isAllowed | boolean | Whether access is permitted. |
isLoading | boolean | Guard check in flight. |
shouldRedirect | boolean | Whether the caller should redirect. |
redirectTo | string | undefined | Where to redirect when denied. |
Examples
Protect a route
const {
isAllowed, // boolean
isLoading, // boolean
shouldRedirect, // boolean
redirectTo, // string | undefined
} = useAuthGuard({
requireAuth: true,
requireWorkspace: true,
redirectTo: '/login',
});See also
Source: README.md#useauthguard · Also available in llms-full.txt and registry.json.