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;
Properties
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 | AuthObject | The authentication data for the active user and their current session. |
session | Session | The current session. |
user | User | The current user. |
organization | Organization | The current organization. |
AuthObject
Name | Type | Description |
---|---|---|
sessionId | string | null | The ID of the current session. |
userId | string | null | The ID of the current user. |
actor | ActJWTClaim | null | The JWT actor for the session. |
getToken | () => Promise<string | null> | A function that returns a promise that resolves to the current user's session token; can also be used to retrieve a custom JWT template |
sessionClaims | ClerkJWTClaims | null | The JWT claims for the session. |
orgId | string | undefined | The ID of the current organization. |
orgRole | string | undefined | The role of the current user in the current organization. |
orgSlug | string | undefined | The slug of the current organization. |
orgPermissions | string[] | undefined | The permissions of the current user in the current organization. |
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. |
authorizedParties? | string[] | An allowlist of origins to verify against, to protect your application from the subdomain cookie leaking attack. For example: ['http://localhost:3000', 'https://example.com'] For more information, refer to the reference guide. |
Last updated on October 10, 2023