Skip to content

Commit

Permalink
feat: add getServerSession and SessionProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-jonas committed Dec 11, 2024
1 parent df98c2b commit 039cc74
Show file tree
Hide file tree
Showing 25 changed files with 611 additions and 144 deletions.
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 isInitialLoading: 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": ";\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": "",
"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;
isInitialLoading: boolean;
session: Session | null;
error?: Error;
refetch: () => Promise<void>;
};

// @public (undocumented)
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

0 comments on commit 039cc74

Please sign in to comment.