Returns the current JWT access token from TokenContext. Must be used inside AuthWrapper.
AuthWrapper
Common uses: conditional rendering based on auth state, passing to custom fetch headers.
The access token string, or null if not yet loaded or user is logged out.
null
import { useToken } from "naystack/auth/client";function Navbar() { const token = useToken(); return <Link href={token ? "/dashboard" : "/login"}>{token ? "Dashboard" : "Log in"}</Link>;} Copy
import { useToken } from "naystack/auth/client";function Navbar() { const token = useToken(); return <Link href={token ? "/dashboard" : "/login"}>{token ? "Dashboard" : "Log in"}</Link>;}
const token = useToken();const response = await fetch("/api/custom", { headers: { Authorization: `Bearer ${token}` },}); Copy
const token = useToken();const response = await fetch("/api/custom", { headers: { Authorization: `Bearer ${token}` },});
Returns the current JWT access token from TokenContext. Must be used inside
AuthWrapper.Common uses: conditional rendering based on auth state, passing to custom fetch headers.