问题
We are building a serverless platform consisting of Android and iOS apps build using React Native and on the backend we use Google Cloud Functions and Firebase. Given that some actions are handled by multiple Cloud Functions, we thought it would be a good idea to have the apps Publish to a Pub/Sub topic and then have the different Cloud Functions fire Subscribe events when the apps publish. Is it good practice to have a React Native app Publish directly to a Google Pub/Sub topic or should we have an HTTPS Cloud Function do the topic publishing?
If it is good practice for the apps to do the Pub/Sub, any tips on how to handle the credentials? There is a Node.js client but not a React Native one in particular. The main issue seems to be with the environmental variable you are supposed to set (e.g. export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/[FILE_NAME].json").
Thanks!
回答1:
If you are going to communicate with firebase (or any server) from the client´s device, best practice is so that you use clients authentication, and not some secure token for all.
There is the benefit, that firebase comes with client authentication.
I would look into 2 ways.
- use firebase directly as a queue. it´s actually capable of doing that just fine and comes automatically with firebase authentication. (see https://github.com/firebase/firebase-queue)
- use firebase cloud functions. The benefit is, authentication is automatically included if you logged in the user with firebase authentication. From there, you can write a simple cloud function to add data to your queue. (see https://firebase.google.com/docs/functions/callable)
来源:https://stackoverflow.com/questions/50352630/is-it-good-practice-to-have-a-react-native-app-publish-directly-to-a-google-pub