witty-noon-28853
06/16/2025, 2:34 PMbrief-egg-61061
06/16/2025, 2:34 PMbrief-egg-61061
06/16/2025, 2:34 PMreturn_to
), you should extract the relevant query parameters from the current URL and append them to the login URL when rendering the link. The Ory documentation and example code for custom UIs show that the default templates often include a section like this for navigation links: handlebars {{#if loginUrl}} <a href="{{loginUrl}}">Log in</a> {{/if}}
In the Express/Handlebars example, the loginUrl
is constructed by reusing the return_to
parameter from the current request: js const initLoginFlow = new URLSearchParams({ return_to: return_to.toString(), }); const loginUrl = getUrlForFlow("login", initLoginFlow);
This ensures that if the recovery flow was started with a return_to
parameter, it is also included in the login link. You should replicate this logic in your Next.js/React code by reading the current search parameters and constructing the login URL accordingly. Example in Next.js/React: jsx import { useRouter, useSearchParams } from "next/navigation" export function BackToSignInLink() { const searchParams = useSearchParams() const params = searchParams.toString() const loginUrl = `/login${params ? `?${params}` : ""}` return <a href={loginUrl}>Back to Sign In</a> }
This approach matches the pattern used in Ory's own templates and ensures that all query parameters are preserved when navigating back to the sign-in page. If you are using Ory Elements, you may need to manually add this link to your custom recovery page, as the default Ory Elements recovery page does not automatically include it with preserved parameters. Summary: - Extract the current search parameters. - Append them to the login URL. - Render the link in your custom recovery page. This mirrors the behavior of the default Ory Account Experience and is the recommended approach based on the official Ory documentation and example code for custom UIs [see "Create recovery flow"](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-basic-integration#create-recovery-flow).witty-noon-28853
06/16/2025, 2:36 PMflow
that does not seem to contain the necessary information for me to build the link myself, so the suggested approach will not workbrief-egg-61061
06/16/2025, 2:36 PMbrief-egg-61061
06/16/2025, 2:36 PMflow
parameter, and the original search parameters (such as return_to
) are not present in the URL anymore. This makes it difficult to reconstruct the original login link with all the intended parameters from within the recovery flow page. Based on the Ory documentation and issues, here’s what is known: - The return_to
parameter is meant to be passed when initializing a flow (e.g., /self-service/recovery/browser?return_to=...
). However, once the flow is created, the browser is redirected to a URL containing only the flow
parameter, and the original query parameters are not automatically persisted in the URL or exposed in the flow object for easy reconstruction of navigation links [Advanced redirects](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-advanced-integration). - The Ory documentation and example code for custom UIs show that you must manually persist the return_to
parameter across flows if you want to maintain it, for example, by extracting it from the flow object and passing it to new flows. However, the flow object itself does not expose all original search parameters—only the return_to
(if set) [Advanced redirects](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-advanced-integration). - There is no built-in mechanism in Ory Kratos or Ory Elements to reconstruct the original login link with all search parameters once you are inside a recovery flow and only have the flow
parameter available. This limitation is also discussed in community issues, where users note that the return_to
parameter does not automatically persist across flows and must be handled manually [SPA flows do not continue with OAuth flow after registration](https://github.com/ory/network/issues/352), [No returnTo being returned](https://github.com/ory/network/issues/51). Conclusion: I'm sorry, but the knowledge sources do not provide a way to reconstruct the original login link with all search parameters from within the recovery flow if those parameters are not explicitly persisted elsewhere (e.g., in local storage, a cookie, or passed through the flow object). The recommended approach is to persist any parameters you need before starting the recovery flow, so you can reconstruct the link as needed. If you only have the flow
parameter, you cannot reliably rebuild the original login link with all search parameters using only the information available in the flow object or URL. If you need this functionality, you will need to implement your own mechanism to persist the original parameters before the flow is initialized and retrieve them when rendering the "Back to Sign In" link [Advanced redirects](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-advanced-integration).