node-facebook / facebook-node-sdk

Modeled from the (Facebook Javascript SDK), now with the facebook-node-sdk you can now easily write the same code and share between your server (nodejs) and the client (Facebook Javascript SDK).
Other
529 stars 114 forks source link

Support isomorphic web applications with a wrapper for Facebook's official client-side SDK #152

Open dantman opened 6 years ago

dantman commented 6 years ago

This SDK is not intended and should not be used inside the browser. Facebook provides an official client-side JavaScript library for this.

However I understand that it is sometimes desirable to be able to import FB from 'fb'; on an isomorphic web application. So that you have access in both the client and server.

My normal recommendation on this is to roll your own wrapper. Write a file that imports fb on the server and sets it up. And a browser version of that file that exports the global window.FB.

https://github.com/node-facebook/facebook-node-sdk/issues/129#issuecomment-359261107

However I do admit this library has some nice features such as the Promise mode of FB.api that would be nice to have in the browser which everyone rolling their own wrapper has to implement.

For this reason I think we could at least help make rolling an isomorphic wrapper easier. We can do this by offering a fb/browser module that will simply re-export the window.FB from Facebook's official client-side SDK, but wrap it with a few of our custom features.

Namely we would make these available in the browser:

Keep in mind that there are significant differences in how things work in the client and on the server:

However if I am to implement this, someone needs to test it and make sure it works. It's not as easy to write tests to make sure an isomorphic API is useful in practice.