Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: add getServerSession and SessionProvider #309

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@ const config = tseslint.config([
"!.storybook",
"**/dist/**",
"**/storybook-static/**",
"babel.config.js",
"eslint.config.mjs",
"**/*.config.{js,mjs,cjs,ts}",
"**/playwright-report/**",
"examples/nextjs-spa/**", // This project is not maintained
"**/playwright.config.{js,ts}",
"**/playwright-ct.config.ts",
"**/jest.config.{js,ts}",
"**/jest.preset.{cjs,ts}",
"playwright/**",
"**/tsup.config.{js,ts}",
"**/.next/**",
],
},
eslint.configs.recommended,
Expand Down
59 changes: 47 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

160 changes: 144 additions & 16 deletions packages/elements-react/api-report/elements-react-client.api.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,53 +173,181 @@
"preserveMemberOrder": false,
"members": [
{
"kind": "Function",
"canonicalReference": "@ory/elements-react!useSession:function(1)",
"docComment": "/**\n * A hook to get the current session from the Ory Network.\n *\n * Usage:\n * ```ts\n * const { session, error, isLoading } = useSession()\n * ```\n *\n * @returns The current session, error and loading state.\n */\n",
"kind": "TypeAlias",
"canonicalReference": "@ory/elements-react!SessionContextData:type",
"docComment": "",
"excerptTokens": [
{
"kind": "Content",
"text": "useSession: (config?: "
"text": "type SessionContextData = "
},
{
"kind": "Content",
"text": "{\n sdk: {\n url: string;\n };\n}"
"text": "{\n isLoading: boolean;\n initialized: boolean;\n session: "
},
{
"kind": "Reference",
"text": "Session",
"canonicalReference": "@ory/client-fetch!Session:interface"
},
{
"kind": "Content",
"text": ") => "
"text": " | null;\n error: "
},
{
"kind": "Reference",
"text": "Error",
"canonicalReference": "!Error:interface"
},
{
"kind": "Content",
"text": "{\n session: "
"text": " | undefined;\n refetch: () => "
},
{
"kind": "Reference",
"text": "Session",
"canonicalReference": "@ory/client-fetch!Session:interface"
"text": "Promise",
"canonicalReference": "!Promise:interface"
},
{
"kind": "Content",
"text": "<void>;\n}"
},
{
"kind": "Content",
"text": " | undefined;\n error: string | undefined;\n isLoading: boolean;\n}"
"text": ";"
}
],
"fileUrlPath": "dist/client/useSession.d.ts",
"fileUrlPath": "dist/client/session-provider.d.ts",
"releaseTag": "Public",
"name": "SessionContextData",
"typeTokenRange": {
"startIndex": 1,
"endIndex": 8
}
},
{
"kind": "Function",
"canonicalReference": "@ory/elements-react!SessionProvider:function(1)",
"docComment": "/**\n * A provider that fetches the session from the Ory Network and provides it to the children.\n *\n * To use this provider, wrap your application in it:\n * ```tsx\n * import { SessionProvider } from \"@ory/elements-react\"\n *\n * export default function App() {\n * return (\n * <SessionProvider>\n * <MyApp />\n * </SessionProvider>\n * )\n * }\n * ```\n *\n * If you have a session from the server, you can pass it to the provider:\n * ```tsx\n * <SessionProvider session={serverSession}>\n * ```\n *\n * @param props - The provider props\n *\n * @see\n *\n * {@link useSession}\n */\n",
"excerptTokens": [
{
"kind": "Content",
"text": "declare function SessionProvider({ "
},
{
"kind": "Reference",
"text": "session",
"canonicalReference": "@ory/elements-react!~__type#session"
},
{
"kind": "Content",
"text": ": initialSession, children, baseUrl, }: "
},
{
"kind": "Reference",
"text": "SessionProviderProps",
"canonicalReference": "@ory/elements-react!SessionProviderProps:type"
},
{
"kind": "Content",
"text": "): "
},
{
"kind": "Reference",
"text": "react_jsx_runtime.JSX.Element",
"canonicalReference": "@types/react!JSX.Element:interface"
},
{
"kind": "Content",
"text": ";"
}
],
"fileUrlPath": "dist/client/session-provider.d.ts",
"returnTypeTokenRange": {
"startIndex": 3,
"startIndex": 5,
"endIndex": 6
},
"releaseTag": "Public",
"overloadIndex": 1,
"parameters": [
{
"parameterName": "config",
"parameterName": "{ session: initialSession, children, baseUrl, }",
"parameterTypeTokenRange": {
"startIndex": 1,
"endIndex": 2
"startIndex": 3,
"endIndex": 4
},
"isOptional": true
"isOptional": false
}
],
"name": "SessionProvider"
},
{
"kind": "TypeAlias",
"canonicalReference": "@ory/elements-react!SessionProviderProps:type",
"docComment": "",
"excerptTokens": [
{
"kind": "Content",
"text": "type SessionProviderProps = "
},
{
"kind": "Content",
"text": "{\n session?: "
},
{
"kind": "Reference",
"text": "Session",
"canonicalReference": "@ory/client-fetch!Session:interface"
},
{
"kind": "Content",
"text": " | null;\n baseUrl?: string;\n} & "
},
{
"kind": "Reference",
"text": "React.PropsWithChildren",
"canonicalReference": "@types/react!React.PropsWithChildren:type"
},
{
"kind": "Content",
"text": ";"
}
],
"fileUrlPath": "dist/client/session-provider.d.ts",
"releaseTag": "Public",
"name": "SessionProviderProps",
"typeTokenRange": {
"startIndex": 1,
"endIndex": 5
}
},
{
"kind": "Function",
"canonicalReference": "@ory/elements-react!useSession:function(1)",
"docComment": "/**\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 This is a client-side hook and must be used within a React component. On the server, you can use the getServerSession function from `@ory/nextjs` and hydrate SessionProvider with the session. :::\n *\n * @returns The current session, and error or loading state.\n */\n",
"excerptTokens": [
{
"kind": "Content",
"text": "declare function useSession(): "
},
{
"kind": "Reference",
"text": "SessionContextData",
"canonicalReference": "@ory/elements-react!SessionContextData:type"
},
{
"kind": "Content",
"text": ";"
}
],
"fileUrlPath": "dist/client/useSession.d.ts",
"returnTypeTokenRange": {
"startIndex": 1,
"endIndex": 2
},
"releaseTag": "Public",
"overloadIndex": 1,
"parameters": [],
"name": "useSession"
}
]
Expand Down
27 changes: 19 additions & 8 deletions packages/elements-react/api-report/elements-react-client.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,30 @@

```ts

import * as react_jsx_runtime from 'react/jsx-runtime';
import { Session } from '@ory/client-fetch';

// @public
export const useSession: (config?: {
sdk: {
url: string;
};
}) => {
session: Session | undefined;
error: string | undefined;
// @public (undocumented)
export type SessionContextData = {
isLoading: boolean;
initialized: boolean;
session: Session | null;
error: Error | undefined;
refetch: () => Promise<void>;
};

// @public
export function SessionProvider({ session: initialSession, children, baseUrl, }: SessionProviderProps): react_jsx_runtime.JSX.Element;

// @public (undocumented)
export type SessionProviderProps = {
session?: Session | null;
baseUrl?: string;
} & React.PropsWithChildren;

// @public
export function useSession(): SessionContextData;

// (No @packageDocumentation comment for this package)

```
Loading
Loading