🔐 useSupaSession()
Exactly analogous to useSupaUser(), this React hook instead provides the current core Session payload (which includes tokens) matching the authenticated state.
Why use this over useSupaUser?
While useSupaUser returns the User object (which involves decoding account metadata like emails, names, or avatar hashes), useSupaSession() fetches the raw Session object. The session object is highly required if you need to manually pull out access tokens to pass on REST API Bearer injections manually for external servers.
"use client";
import { useSupaSession } from "next-supa-utils/client";
export default function TokenDumper() {
const { session, loading } = useSupaSession();
if (loading) return <div>Checking tokens...</div>;
if (!session) return <div>No valid session found.</div>;
return (
<div className="bg-gray-100 p-4 rounded mt-4">
<h4>Your Bearer Token:</h4>
<textarea readOnly className="w-full text-xs font-mono">{session.access_token}</textarea>
</div>
);
}
Return API (UseSupaSessionReturn)
| Property | Type | Description |
|---|---|---|
session | Session | null | The Session payload from Supabase. |
loading | boolean | Resolves standard React suspension while checking token availability in browser cache chunks. |
error | SupaError | null | Detailed error state if tokens were corrupted or malformed. |