Skip to content

Commit cb6284b

Browse files
committed
feat: document transient payload passthrough in elements
1 parent eddc314 commit cb6284b

1 file changed

Lines changed: 73 additions & 0 deletions

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
id: transient-payload
3+
title: Transient Payload passthrough
4+
sidebar_label: Transient Payload
5+
---
6+
7+
Transient payload is an Ory Kratos concept, that allows users of the APIs to pass data through to webhooks. All self-service Kratos flows support transient payloads, and they are passed through to the webhooks as JSON objects. This allows you to use the data in your webhooks, for example to customize the user experience or to trigger specific actions based on the data.
8+
9+
Ory Elements allows defining transient payloads on the self-service flow components. To do this, you can use the `transientPayload` prop on the self-service flow components. The value of this prop should be an object that contains the data you want to pass through to the webhooks or a function that returns such an object. The data will be passed through to the webhooks as JSON objects.
10+
11+
12+
## Static Transient Payload
13+
14+
In this example, we define a static transient payload that contains the user's preferred language. This data will be passed through to the webhooks as a JSON object.
15+
16+
```tsx
17+
import { Registration } from "@ory/elements-react/theme"
18+
import { getRegistrationFlow, OryPageParams } from "@ory/nextjs/app"
19+
20+
import config from "@/ory.config"
21+
import { headers } from "next/headers"
22+
23+
export default async function RegistrationPage(props: OryPageParams) {
24+
const flow = await getRegistrationFlow(config, props.searchParams)
25+
26+
const language = (await headers()).get("Accept-Language")
27+
28+
if (!flow) {
29+
return null
30+
}
31+
32+
return (
33+
<Registration
34+
flow={flow}
35+
config={config}
36+
components={{
37+
Card: {},
38+
}}
39+
transientPayload={{
40+
language
41+
}}
42+
/>
43+
)
44+
}
45+
46+
```
47+
48+
## Dynamic Transient Payload
49+
50+
In this example, we define a dynamic transient payload that contains the user's preferred language. The function is called, when the user submits the form, and the API request is made. This allows you to pass dynamic data to the webhooks, based on the user's input or other factors.
51+
52+
```tsx
53+
"use client"
54+
55+
import { Registration } from "@ory/elements-react/theme"
56+
import { RegistrationFlow } from "@ory/client-fetch"
57+
import config from "@/ory.config"
58+
59+
export function RegistrationWithPayload({ flow }: { flow: RegistrationFlow }) {
60+
return <Registration
61+
flow={flow}
62+
config={config}
63+
transientPayload={(formValues) => {
64+
const referalCode = localStorage.getItem("referal-code")
65+
return {
66+
referalCode,
67+
}
68+
}}
69+
/>
70+
}
71+
```
72+
73+
The function also receives the form values as an argument, which allows you to use the user's input to determine the transient payload. In this example, we are retrieving a referral code from local storage and passing it through to the webhooks.

0 commit comments

Comments
 (0)