<@U04UQ68083H> if a client inits a self-service lo...
# ory-copilot
i
@chilly-king-10285 if a client inits a self-service login flow with a return_to and is then redirected to my custom ui, can I use the initiated flow id also for registration? think about the case: user is redirected to /login but then clicks on /register
b
A message from kapa.ai
When a user initiates a login flow with a
return_to
parameter and then decides to register instead, the
return_to
parameter doesn't automatically persist across different flows. However, you can extract the
return_to
URL from the login flow and use it when creating a new registration flow. According to the documentation on advanced redirects: > The
return_to
query parameter doesn't automatically persist across different flows and must be added to new flows. For example, if the user starts a login flow with
return_to
URL set and then switches to a registration flow, the
return_to
URL isn't used for the registration flow. In such a case, your application can re-use the same
return_to
from the login flow by extracting the
return_to
URL from the login flow's
flow.return_to
and adding it to the registration flow. Here's how you can implement this in your custom UI:
Copy code
javascript sdk.getLoginFlow({ id: flow }).then(({ data: flow }) => {   const returnTo = flow.return_to   return sdk.createBrowserRegistrationFlow({     id: flow.id,     return_to: returnTo,   }) })
This approach allows you to maintain the original
return_to
destination when users switch from login to registration [Advanced integration](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-advanced-integration). There have been issues with this functionality in the past. For example, GitHub issue #119 mentioned that the
return_to
parameter was not being honored when registering from a login flow, but this has been fixed [GitHub Issue #119](https://github.com/ory/network/issues/119). Additionally, for OAuth flows, there was a similar issue (#264) about transferring the
redirect_uri
parameter from Hydra to the login
return_to
parameter [GitHub Issue #264](https://github.com/ory/network/issues/264). So in summary, you can use the flow ID for fetching the login flow data, extract the
return_to
parameter, and then create a new registration flow with that same
return_to
parameter.