<@U04UQ68083H> when on a custom login page with a ...
# ory-copilot
w
@chilly-king-10285 when on a custom login page with a flow object, where in that flow object does it say where to go after the login process is completed successfully? I need to create a link that will definitely get the user back to the page they visited before being redirected to the login page
c
A message from kapa.ai
When you initialize a login flow in Ory (e.g., by calling `/self-service/login/browser?return_to=https://myapp.com/protected`), the URL you want the user to be redirected to after a successful login is passed as the
return_to
query parameter. This value is then stored in the flow object. In the flow object, the property you are looking for is
return_to
.
This property tells you where the user should be redirected after a successful login. If you want to create a link or button that takes the user back to the page they visited before being redirected to the login page, you should use the value of
flow.return_to
. Here’s how it works: - When you create the login flow, include the
return_to
parameter with the URL of the page the user was originally trying to access. - The flow object returned by Ory will contain a
return_to
property with this URL. - After a successful login, Ory will redirect the user to the URL specified in
return_to
. - If you want to create a manual link (e.g., "Back to previous page"), use the value of
flow.return_to
for the link’s destination. Example:
Copy code
js const returnTo = flow.return_to // Use returnTo as the href for your "Back" link or button
Important: - The
return_to
URL must be allow-listed in your Ory configuration to prevent open redirect attacks. - If the
return_to
property is not set, Ory will use the default redirect URL configured for your project. References: - [Advanced redirects: flow.return_to](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-advanced-integration) - [Redirection and return_to parameter](https://www.ory.sh/docs/kratos/concepts/browser-redirect-flow-completion#redirection)