frappe-react-sdk: socketio throwing CORS error when using the SDK on a cross domain app
I’m implementing an app where the frontend is hosted separately on a different domain and use frappe as the backend. Then all the requests that go to the frappe API are cross origin requests.
Let’s assume my frappe site is in myapp.frappe.cloud and my react app is in app.myorg.com.
I have tried setting allow_cors config in site_config.json in the frappe site. It fixed the initial CORS issue that we get when we send the login request. Now after I login with https://myapp.frappe.cloud/api/method/login, I see 2 issues:
- The cookies returned by the frappe site has
Same-Site: Laxwhich is expected - When I send a subsequent request to the frappe API, cookies (returned above at login success) are note sent. Tt suree client should have
withCredentials: trueoption set for this to work.
I’m not sure if this needs to be address in this library or https://github.com/The-Commit-Company/frappe-js-sdk repo. But I believe this is a much needed thing.
I’m happy to assist in any development needed.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 16 (7 by maintainers)
Hey @asharamseervi ,
Two things won’t work with React Native - cookie based authentication and Socket events. For authentication, you’ll have to to use token based auth - which is supported by the SDK. All other hooks will work since it’s using Axios under the hood.
Hussain Nagaria has a Build With Hussain episode on YouTube wherein he uses frappe-js-sdk to build a React Native app with Frappe.
We tried using frappe-React-SDK for Raven’s mobile app using React Native, but since socket events were critical for Raven, we decided to not continue with RN (among other reasons). If you don’t want real-time events, you can use the SDK. If you want real-time events, you can try contributing to the Frappe core so that it supports socket events with token based auth.
Thanks!
@IMS94 We are working with the Frappe team to add support for Socket for Non-native environments like React Native.
SocketIO should ideally work in cross domain, but I guess since it’s cookie based, it’s not working as of now.
Regardless, I’ll add an option to disable Socket in the library.