From c3dcbf2dda3511909bd29e623b1eebb376331cc3 Mon Sep 17 00:00:00 2001 From: Nick Nisi Date: Thu, 10 Apr 2025 10:21:03 -0500 Subject: [PATCH] add section about passing data through authentication flows to README --- README.md | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/README.md b/README.md index 677a811..1f0529f 100644 --- a/README.md +++ b/README.md @@ -116,3 +116,46 @@ The following claims may be populated if the user is part of an organization: - `organizationId`: The currently-selected organization. - `role`: The `role` of the user for the current organization. - `permissions`: Permissions corresponding to this role. + +## Passing Data Through Authentication Flows + +When building authentication flows, you often need to maintain state across redirects. For example, you might want to return users to the page they were viewing before login or preserve other application state. AuthKit provides a way to pass and retrieve data through the authentication process. + +### Using `state` + +`state` is used to pass data that you need to retrieve after authentication completes + +```tsx +// When signing in, pass your data using the state parameter +function LoginButton() { + return ( + + ); +} + +// Then retrieve your data in the onRedirectCallback +function App() { + return ( + { + // Access your data here + if (state?.returnTo) { + window.location.href = state.returnTo; + } + }} + > + + + ); +} +``` + +This pattern works with both `signIn` and `signUp` functions.