-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat: document transient payload passthrough in elements #2499
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
Merged
+84
−0
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cb6284b
feat: document transient payload passthrough in elements
jonas-jonas 8d8121c
chore: format
jonas-jonas 52f65a3
Apply suggestions from code review
jonas-jonas 2863c10
Apply suggestions from code review
jonas-jonas 9541e5d
Merge branch 'master' into jonas-jonas/transientPayloadsElements
jonas-jonas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| --- | ||
| id: transient-payload | ||
| title: Transient Payload passthrough | ||
| sidebar_label: Transient Payload | ||
| --- | ||
|
|
||
| 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. | ||
|
vinckr marked this conversation as resolved.
|
||
|
|
||
| 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. | ||
|
vinckr marked this conversation as resolved.
|
||
|
|
||
| - [Read more about webhooks in Ory](../../guides/integrate-with-ory-cloud-through-webhooks.mdx) | ||
|
|
||
| ## Static Transient Payload | ||
|
vinckr marked this conversation as resolved.
|
||
|
|
||
| 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. | ||
|
|
||
| ```tsx | ||
| import { Registration } from "@ory/elements-react/theme" | ||
| import { getRegistrationFlow, OryPageParams } from "@ory/nextjs/app" | ||
|
|
||
| import config from "@/ory.config" | ||
| import { headers } from "next/headers" | ||
|
|
||
| export default async function RegistrationPage(props: OryPageParams) { | ||
| const flow = await getRegistrationFlow(config, props.searchParams) | ||
|
|
||
| const language = (await headers()).get("Accept-Language") | ||
|
|
||
| if (!flow) { | ||
| return null | ||
| } | ||
|
|
||
| return ( | ||
| <Registration | ||
| flow={flow} | ||
| config={config} | ||
| components={{ | ||
| Card: {}, | ||
| }} | ||
| transientPayload={{ | ||
| language, | ||
| }} | ||
| /> | ||
| ) | ||
| } | ||
| ``` | ||
|
|
||
| ## Dynamic Transient Payload | ||
|
vinckr marked this conversation as resolved.
|
||
|
|
||
| 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. | ||
|
vinckr marked this conversation as resolved.
|
||
|
|
||
| ```tsx | ||
| "use client" | ||
|
|
||
| import { Registration } from "@ory/elements-react/theme" | ||
| import { RegistrationFlow } from "@ory/client-fetch" | ||
| import config from "@/ory.config" | ||
|
|
||
| export function RegistrationWithPayload({ flow }: { flow: RegistrationFlow }) { | ||
| return ( | ||
| <Registration | ||
| flow={flow} | ||
| config={config} | ||
| transientPayload={(formValues) => { | ||
|
vinckr marked this conversation as resolved.
|
||
| const referralCode = localStorage.getItem("referral-code") | ||
| return { | ||
| referralCode, | ||
| } | ||
| }} | ||
| /> | ||
| ) | ||
| } | ||
| ``` | ||
|
|
||
| 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. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.