useIsAuthenticated
Boolean authenticated flag.
Import
TypeScript
import { useIsAuthenticated } from '@/hooks';API
Signature
useIsAuthenticated() → boolean
When to use
Use useIsAuthenticated 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 · useIsAuthenticatedEditor
function Gate({ children }: { children: React.ReactNode }) { const ok = useIsAuthenticated(); return ok ? children : <a href="/login">Login</a>; }
Preview
Implementation source
Full library source for useIsAuthenticated — copy into your project when you are not installing a package yet.
hooks/auth/useIsAuthenticated.ts
import { useAuth } from './useAuth';
/** Whether the user is authenticated. */
export function useIsAuthenticated(): boolean {
return useAuth().isAuthenticated;
}
Copy-paste example
useIsAuthenticated.example.tsx
'use client';
import { useIsAuthenticated } from '@/hooks';
export function Gate({ children }: { children: React.ReactNode }) {
const ok = useIsAuthenticated();
return ok ? children : <a href="/login">Login</a>;
}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/useIsAuthenticated.tsfor implementation details