creamy-night-68920
11/10/2024, 8:02 PMbrief-egg-61061
11/10/2024, 8:02 PMbrief-egg-61061
11/10/2024, 8:03 PM/self-service/{flow_type}/api
- For browser flows: Use endpoints at /self-service/{flow_type}/browser
It's crucial to use the correct endpoints for each environment because they implement different security measures. For example, browser flows set CSRF cookies, which are not needed in native apps. [Ory Docs](https://www.ory.sh/docs/kratos/self-service#performing-login-registration-settings--flows) explicitly warn: "Never use API flows to implement Browser applications! Using API flows in Single-Page-Apps as well as server-side apps opens up several potential attack vectors, including Login and other CSRF attacks." Therefore, for your React Native app that also runs on the web, you should implement both types of flows and use them accordingly based on the environment the app is running in.creamy-night-68920
11/10/2024, 8:04 PMbrief-egg-61061
11/10/2024, 8:04 PMbrief-egg-61061
11/10/2024, 8:04 PM<http://kratos.bar.com|kratos.bar.com>
and <http://ui.bar.com|ui.bar.com>
will work, but <http://kratos.bar.com|kratos.bar.com>
and <http://not-bar.com|not-bar.com>
won't. 4. JSON Responses: Set the Accept
HTTP Header to application/json
in your requests. This tells Ory Identities to respond with JSON instead of HTTP redirects. 5. Form Submission: For form submissions, [Ory Docs](https://www.ory.sh/docs/kratos/self-service#form-submission-and-payload-validation-1) recommend intercepting the submission and sending the form as JSON using fetch
or the Ory SDK. 6. Flow Initialization: To start a flow (like login or registration), make a GET request to the appropriate endpoint. For example, for login: javascript const response = await fetch('https://$<http://PROJECT_SLUG.projects.oryapis.com/self-service/login/browser|PROJECT_SLUG.projects.oryapis.com/self-service/login/browser>', { headers: { 'Accept': 'application/json' } }); const flow = await response.json();
7. Form Rendering and Submission: Use the flow data to render your form and handle submissions. [Ory Docs](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-basic-integration#single-page-application-1) provide an example: "For example, login is a POST request to https://$<http://PROJECT_SLUG.projects.oryapis.com/self-service/login/browser?flow=<id|PROJECT_SLUG.projects.oryapis.com/self-service/login/browser?flow=<id>>
." For a practical example, you can refer to the [Next.js UI Reference Implementation](https://github.com/ory/kratos-selfservice-ui-react-nextjs) mentioned in the [Ory Docs](https://www.ory.sh/docs/kratos/bring-your-own-ui/configure-ory-to-use-your-ui#reference-implementations-and-examples). Remember, always use browser flows for your Next.js app, even if it's a SPA, to ensure proper security measures are in place.