I'm following the <self-service flow for user regi...
# ory-network
e
I'm following the self-service flow for user registration and using both curl or Go I'm able to register but testing the fail case of a weak password and instead of getting json back from the request I get an html page. I thought this was because I left the UI for registration still set to /ui/registration (the managed ui). So I changed it to
<http://localhost:3000/signup>
and now it returns that html. Am I wrong in thinking I'd get json back like shown here?
p
Hi @User You can receive json back when the request is made via Ajax / curl. If you are using the browser flow (server-side rendered) it will redirect you back to the registration url.
e
@User, looks like with the server-side browser flow on registration if there was an error that ory would redirect back to the defined registration page but wouldn't provide any way to get an error message back to the user. I was looking to make the request and get json back that I could then use to render the registration page with the appropriate message like: "weak password", "email already registered", "not a valid email", etc.
p
Hi @User You can get the error messages through the json payload that you get before rendering your UI. You can do an API call with the redirected URL flow id to get the UI nodes and error messages. How are you rendering the registration page currently then? https://www.ory.sh/docs/kratos/self-service#form-submission-and-payload-validation https://www.ory.sh/docs/kratos/concepts/ui-user-interface
See this diagram. On validation error it does a redirect back to your registration page and now before you render that page you will fetch the UI nodes on your server (since this is server-side rendered). The server will most likely use the UI nodes to build the form and layout, here you can also add error messages since they are contained in the same payload.
e
Hi @User, It's good to know I can access the error information via an additional API call. That will work for me. I think the only thing I'm stuck on at the moment is getting the API call right. As an example I can make the following three calls, with the last curl call to the API to get the error messages:
Copy code
fn sendRegistration {|email passw|
 var cookie = (mktemp)
 var first = (curl -s -X GET --cookie-jar $cookie -H "Accept: application/json" "<https://ory.zenvolution.tech/self-service/registration/browser>" | from-json)
 curl -i --cookie $cookie -X POST $first[ui][action] -H 'Content-Type: application/x-www-form-urlencoded' -d 'method=password&traits.email='$email'&password='$passw'&csrf_token='$first[ui][nodes][0][attributes][value]
  curl -s -S -i -X GET --cookie $cookie --cookie-jar $cookie -H "Accept: application/json" '<https://ory.zenvolution.tech/api/kratos/public/self-service/registration/flows?id='$first[id]>
}
If I give this shell function a bad email and password I'm hoping the last curl call to the API would give me the error json, but I believe I do not have the URL correct. It's difficult to figure this out this the documentation you pointed to, plus I believe it is referring to kratos rather then cloud (I know it's technically the same, but there seems to be some differences). Can you help me get the right URL for the API call?
p
Hi @User I think it would be best to check out this example repository https://github.com/ory/kratos-selfservice-ui-node