Skip to main content

useApiAuthAppSession

The useApiAuthAppSession hook loads API auth app portal session context, including ticket exchange support.

Parameters

ticket
string | null
Optional session ticket to exchange before loading the API auth app session.

Return Value

hasSession
boolean
Whether the request has an active API auth session.
sessionLoading
boolean
Whether ticket exchange or session loading is in progress.
sessionError
Error | null
Error from ticket exchange or session loading.
sessionId
string | null
Current API auth app session ID.
apiAuthApp
ApiAuthAppInfo | null
API auth app metadata for the current session.
ticketExchanged
boolean
Whether the ticket exchange completed successfully.
ticketLoading
boolean
Whether ticket exchange is currently in progress.
refetch
() => Promise<void>
Revalidate session data.

Example

import { useApiAuthAppSession } from "@wacht/react-router";

function ApiAuthPortal({ ticket }: { ticket?: string }) {
  const { hasSession, sessionLoading, apiAuthApp } = useApiAuthAppSession(ticket);

  if (sessionLoading) return <div>Loading...</div>;
  if (!hasSession) return <div>No session</div>;

  return <h1>{apiAuthApp?.name}</h1>;
}