Docs / auth / useAuthGuard

useAuthGuard

hook

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

ParamTypeNotesDescription
options.requireAuthbooleanRequire an authenticated session.
options.requireWorkspacebooleanRequire a selected workspace.
options.redirectTostringPath to redirect to when access is denied, e.g. '/login'.

Returns

FieldTypeDescription
isAllowedbooleanWhether access is permitted.
isLoadingbooleanGuard check in flight.
shouldRedirectbooleanWhether the caller should redirect.
redirectTostring | undefinedWhere 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

useAuth · AuthGuard

Source: README.md#useauthguard · Also available in llms-full.txt and registry.json.