UNPKG

@easyyo/ory.elements-react

Version:

Ory Elements React - a collection of React components for authentication UIs.

1 lines 1.24 kB
{"version":3,"sources":["../../src/client/useSession.ts"],"sourcesContent":["// Copyright © 2024 Ory Corp\n// SPDX-License-Identifier: Apache-2.0\n\"use client\"\n\nimport { useContext } from \"react\"\nimport { SessionContext } from \"./session-provider\"\n\n/**\n * A hook to get the current session from the Ory Network.\n *\n * Usage:\n * ```ts\n * const session = useSession()\n *\n * if (session.state == \"loading\") {\n * return <div>Loading...</div>\n * }\n *\n * if (session.state == \"authenticated\") {\n * return <div>Session: {session.session.id}</div>\n * }\n * ```\n *\n * :::note\n * This is a client-side hook and must be used within a React component.\n * On the server, you can use the getServerSession function from `@ory/nextjs`\n * and hydrate SessionProvider with the session.\n * :::\n *\n * @returns The current session, and error or loading state.\n */\n\nexport function useSession() {\n if (!SessionContext) {\n throw new Error(\"[Ory/Elements] useSession must be used on the client\")\n }\n return useContext(SessionContext)\n}\n"],"mappings":";AAIA,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AA2BxB,SAAS,aAAa;AAC3B,MAAI,CAAC,gBAAgB;AACnB,UAAM,IAAI,MAAM,sDAAsD;AAAA,EACxE;AACA,SAAO,WAAW,cAAc;AAClC;","names":[]}