Hooks

useUser

The useUser hook is the primary way to access the current session state and user profile information within your Client Components.

Usage

Destructure the user object and status indicators directly from the hook:

terminal
import { useUser } from "@ezz-auth/next";

export default function ProfileHeader() {
  const { user, isAuthenticated, isLoading } = useUser();

  if (isLoading) return <div>Loading...</div>;

  return (
    <div>
      {isAuthenticated ? (
        <p>Welcome back, {user.name}!</p>
      ) : (
        <p>Please sign in.</p>
      )}
    </div>
  );
}

Return Values

user

The profile object containing ID, email, and metadata.

isAuthenticated

A boolean indicating if a valid session exists.

isLoading

True while the AuthProvider is fetching the session.

Security

No Token Exposure

Authentication tokens are never exposed to the client-side JavaScript environment.

No Cookie Access

The hook does not interact with document.cookies, preventing unauthorized tampering.

Server Validated

User data is provided via a secure, server-validated session managed by the AuthProvider.