Skip to content

useSession

Exposes the current session validation status from the StudioProvider.

Import

ts
import { useSession } from "@asset-studio/core";

Usage

tsx
function SessionGuard() {
  const { sessionStatus } = useSession();

  if (sessionStatus === "loading") return <p>Validating session...</p>;
  if (sessionStatus === "expired" || sessionStatus === "error")
    return <p>Session invalid.</p>;
  return <p>Session active</p>;
}

Return Value

PropertyTypeDescription
sessionStatusSessionStatusCurrent session status.
errorFallbackReactNode | undefinedFallback UI passed to StudioProvider via the errorFallback prop.

Types

ts
type SessionStatus = "loading" | "valid" | "expired" | "error";

Notes

  • The session check is made once on mount of StudioProvider.
  • While sessionStatus is 'loading', the editor will not render visible content.
  • On 'expired' or 'error', the errorFallback from the provider is rendered if provided.

Released under a proprietary license.