Tuesday 23 May 2017

Firebase Cloud Functions-Knowing which user has written the data in onWrite

I'm trying to make a simple messaging app. In the process, I want to use firebase's cloud function feature for functions that should not be carried out client-side for the sake of security. Many of the functions I want to be called whenever the user wants. The way I'm trying to do it now is by having clients push little 'function request' objects under a single parent so that the onWrite function will fire off and I can parse the request object to execute the function. (The reason I'm not using http functions is because I want some way to securely know which user has made the request). The problem is I can't find a way in firebase's documentation to know which user wrote the data.

in index.js I have

exports.requestFunction = functions.database.ref('/function-
requests/{pushId}')
.onWrite(event => {
// Parse event.data.val() for things like the function name and its
// parameters. Then actually call the function.
// Ideally I would also be able to parse event somehow to find the user
// who saved the data.
});

Please note that I have considered including the user id as a parameter, but that's too unsafe as any user can pretend to be another user by giving a different uid.



via WWB Messaging

No comments:

Post a Comment