pocketbase / js-sdk

PocketBase JavaScript SDK
https://www.npmjs.com/package/pocketbase
MIT License
2.06k stars 122 forks source link

Can't use pocketbase on React Native. #114

Closed niputy closed 1 year ago

niputy commented 1 year ago

Hey! I tried to use pocketbase with React Native and get error: ClientResponseError 0: Something went wrong while processing your request. Can someone please confirm that pocketbase is not working on React Native and it's possible to add support for React Native too?

ganigeorgiev commented 1 year ago

The SDK has no dependency other than fetch and EventSource for the realtime service, so it should work with React Native.

Could you provide a little more details about the error (you could try to console.log(err.originalError) and paste here the full stack trace)? How you are initializing the project? What version of node, ts, react native you are using?

ganigeorgiev commented 1 year ago

@niputy I'm closing the issue since I'm not able to reproduce it (tested with Expo). Please provide the full error stack trace and/or a code sample how you initialize the SDK and what method calls you are making.

niputy commented 1 year ago

Looks like it's http issue described here. console.log(err.originalError)show TypeError: Network request failed I used latest versions of everything, you actually can test on my app here. It's possible to change pocketbase url from http to https?

ganigeorgiev commented 1 year ago

It's possible to change pocketbase url from http to https?

You can start the PocketBase executable with --https="yourdomain.com:443" but it'll issue a Let's encrypt certificate and expects a valid public domain (it will not work with bare IPs).

It is hard to debug what exactly is the issue since the error is too generic and there is no stack trace attached. Make sure that your device have access to the PocketBase url address (in your code it is 127.0.0.1 but if you are running inside an emulator you have to use 10.0.2.2 per https://developer.android.com/studio/run/emulator-networking#networkaddresses and eventually maybe bind PocketBase to all IPv4 interfaces with ./pocketbase serve --http="0.0.0.0:8090").

niputy commented 1 year ago

Omg, I just change 127.0.0.1 to 10.0.2.2 and now it's working. Thank you very much! Issue was resolved.

dannyvidal commented 1 year ago

I know its been a while but if anyone comes across this issue you can use ngrok.

ngrok http 8090 
# Or whatever port you have pocketbase set to.

note: you do have to make an account but it is free.

NoCluePS commented 10 months ago

@ganigeorgiev , so it's not possible to have realtime in react-native?

ganigeorgiev commented 10 months ago

@NoCluePS I don't know how did you come to this conclusion.

It should work fine but you'll have to load EventSource polyfill (see the note in https://github.com/pocketbase/js-sdk#nodejs-via-npm). Also if you are testing on Android in debug mode please check the linked resources in https://github.com/pocketbase/pocketbase/discussions/2484#discussioncomment-6118523.

If you are still not able to make it work, feel free to open a Q&A discussion in the main repo with more details about your setup and how are you testing and I'll try to investigate it.

NoCluePS commented 10 months ago

Sorry, didn't refresh hard enough apparently :D