Firebase - 'pushWithPriority' - and validation

为君一笑 提交于 2019-12-12 15:43:53

问题


I really want to 'push with priority'. But this doesn't exist, so I am planning on doing a push with out parameters, then a setWithPriority with the returned reference. Similar to the example in the docs.

var messageListRef = new Firebase('https://samplechat.firebaseio-demo.com/message_list');
var newMessageRef = messageListRef.push();
newMessageRef.set({ 'user_id': 'fred', 'text': 'Yabba Dabba Doo!' });

but more like

var messageListRef = new Firebase('https://samplechat.firebaseio-demo.com/message_list');
var newMessageRef = messageListRef.push();
newMessageRef.setWithPriority({ 'user_id': 'fred', 'text': 'Yabba Dabba Doo!' },1000);

What I can't find is what happens to validation, call backs on the empty push?

Does it try to create an empty node - firing the validation and call backs etc?

Or does it just return a reference that is (sort of) guaranteed to be unique of all other pushes to that parent? With the 'add child'/validation etc firing only on the 'set'?

Edit

Ok. Having had it confirmed that there is no server side interaction on an parameterless Push - my code now reads:

var ref = window.lastref.child("Offers").push();
ref.setWithPriority(spaceof.data, Firebase.ServerValue.TIMESTAMP,function (data) { $("body").prepend(data); }

The firebase timstamp successfully gives a serverside timestamp as a priority, I intend to use this priority for garbage collection - deleting old 'offers' that have been laying around.

To prevent clientside spoofing I'll be looking to add a validation/security rule that the priority of a new node has to be with in a few seconds of the actual serverside timestamp (if I get stuck, I'll be back!).


回答1:


Push simply creates a unique id and returns a reference to it. It is a pure client-side operation, so no server-side validations (e.g. Firebase's security rules) are triggered.



来源:https://stackoverflow.com/questions/28561758/firebase-pushwithpriority-and-validation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!