Hi, how can I override the default return_to after...
# talk-kratos
s
Hi, how can I override the default return_to after submitting a profile form update from self-service UI? (for example, including hidden field on the form for return_to? etc?). The use case is I want it to return to email verification screen if email is updated, else refresh to settings page. after: profile: default_browser_return_url: http://127.0.0.1:3000/xxx
b
Following up on this
Seems like a common use case, has anyone encountered the same situation?
m
You can pass the return_to query parameter when initializing the flow
That URL has to be whitelisted in the config
b
Thanks for the reply, I believe the doc isn't very clear here on what it means to “pass return to when initializing the flow”. For profile, what is initializing the flow, is there an example. As far as I know the flow is just the settings flow, but there are multiple return to possibilities (after profile change, after password change, etc)
m
I see what you mean, the answer then was for the login/register routes, let me check how it would work with settings.
b
Yea the specific config I want to set dynamically in code is after>profile>return_to
m
Hey Kevin, did not have the chance to test it on my machine, just letting you know that I did not forget it, and will do some testing as soon as I get the chance.
👍 1
b
Thanks
Hi Vincent, looking to resolve this before the holidays, if you don't have time to test I'd just like to see an example of this with any other flow from self service and figure it out from there.
m
Hey @stocky-pager-63161 did not have the chance to test it, but will do so over the holidays. your URL would look like so:
/self-service/verification/browser?return_to=<http://app.domain.com>
b
Ok looking
s
Hello @magnificent-energy-493, happy new years, hope you had a good holidays. I have still not managed to figure out how to achieve what i'd like to do with this setting: settings: ui_url: http://127.0.0.1:3000/settings privileged_session_max_age: 15m after: profile: default_browser_return_url: http://127.0.0.1:3000/verify Profile has different user traits, i.e. email, name etc. I'd like it such that ONLY if the user updates email, I redirect them to a specific page, else they can go to the default return url. I cannot set this "return url" for a profile update dynamically in code, the example you gave for verification doesn't seem to apply to settings, and even if it did, I cannot predict whether or not users will update email when fetching the flow, it has to be set when they submit the form. Could you please help take a look at this? I assume it is a fairly straightforward usecase
m
I see, so at the moment it is redirecting no matter what trait you change, but you want it to only redirect on the email change 🤔 Apologies I did not get that before, I thought just on the account settings changes in general.
s
Hi, sorry! Yes, I think thats right
In the documented example, there are email and name fields. If I wanted to have page redirect on email change but not on name change, what is the recommended way to do so?
m
No my bad, I actually have to look a bit how to do that. Will name change also be possible? If the only trait to be changed is the email you can just omit the others in the frontend.
s
Yea, unfortunately in my case I have a few other traits (language preference,etc, that follows the user's profile), so they have to be changed
m
Ok I will ask around! Should be solvable since you have total control over the frontend.
s
awesome, thanks
So far, my best solution has been to not set default return to, have kratos auto redirect back to settings with status success, and then check if email verification has "sent" as status. This doesn't work in the edge case that users have unverified email but do not change it (i..e they update something else). So I'd still prefer finding a way to set the return to when profile form is submitted
^because in this case email status would be "sent". The hacky way around this would be to check when this email was last updated... but that gets into other issues (assume it takes 5 seconds to redirect? 10?). If there was something returned via settings like which fields just got updated (along with that status success) it would resolve this issue as well.
Usually when a form is posted, the updated fields are sent back. In this case, kratos sends back ALL new fields for the identity, so we can't know which fields changed.
m
Hey Kevin, looked into it a bit more, but it seems this is not as easy as we would like. You probably have to solve this in the settings UI and have to find some solution in the frontend. I will still look for a better/more concrete solution, but this is the best I could come up with up until now.
b
Hey Vincent, thanks
My suggestion for an addition is to return the settings updated fields payload
Along with status success
This is pretty standard and allows a lot of flexibility for Frontend