withServerAuth()
Usage
import * as React from 'react'; import { withServerAuth } from 'gatsby-plugin-clerk/ssr'; import { PageProps } from "gatsby"; export const getServerData = withServerAuth( async props => { return { props: { data: '1', auth: props.auth } }; }, { loadUser: true }, ); function SSRPage({ serverData }: PageProps) { return ( <main> <h1>SSR Page with Clerk</h1> <pre>{JSON.stringify(serverData, null, 2)}</pre> </main> ); } export default SSRPage;
Props
withServerAuth
takes two arguments:
function withServer(cb: Callback, options: Options): GetServerDataReturn;
Gatsby then automatically passes the result of withServer
's callback to the serverData
property on the page's component props.
Callback props
Name | Type | Description |
---|---|---|
auth | ServerSideAuth | Current auth data, including sessionId and userId . |
session | Session | The current session. Requires loadSession to be set to true in options. |
user | User | The current user. Requires loadUser to be set to true in options. |
organization | Organization | The current organization. Requires loadOrg to be set to true in options. |
Options
Name | Type | Description |
---|---|---|
loadUser? | boolean | If true , load the user data for the current auth session. |
loadSession? | boolean | If true , load the session data for the current auth session. |
loadOrg? | boolean | If true , load the organization data for the current auth session. |
jwtKey? | string | An optional custom JWT key to use for session token validation. Read more about jwtKey with our docs page. |
authorizedParties? | string[] | An optional list of domains allowed to request JWT authorization. Read more about authorizedParties with our docs page. |