useSession()
Lightweight hook for accessing the current user session. Simplified alternative to useAuth() when you only need session data.
Overview
The useSession() hook provides access to the current session with properties: session (current user session or null), isLoading (whether session is being loaded), and error (error if session loading failed). Use this when you only need to read session data without sign in/out functionality.
Basic Usage
'use client';
import { useSession } from 'authsafe-nextjs';
export default function UserProfile() {
const { session, isLoading } = useSession();
if (isLoading) return <p>Loading...</p>;
if (!session) return <p>Not signed in</p>;
return (
<div>
<p>{session.name}</p>
<p>{session.email}</p>
</div>
);
}