angularjs - Firebase simple login for authentication with the REST api -
i want create web app angularjs , firebase parts of app need 3-way binding firebase offers. other parts work finding binding 1 time current info without updating it. in other words, normal rest api suffice.
the thinkster angularjs-firebase tutorial shows how utilize $resource
access firebase rest api. approach not require open concurrent connection firebase , fetches current info without updating:
app.factory('post', function ($resource) { homecoming $resource('https://firebase-url.firebaseio.com/posts/:id.json'); });
would possible these kind of requests after logging in firebase using simple login service, without keeping firebase connection open. example:
//does open connection firebase? var ref = new firebase('https://firebase-url.firebaseio.com'); //login firebase ref.authwithpassword({ email : "bobtony@firebase.com", password : "correcthorsebatterystaple" }, function(error, authdata) { if (error === null) { // can close connection while still leaving user authenticated? firebase.gooffline(); } else { console.log("error authenticating user:", error); } });
if create requests rest api now:
will firebase recognizeauth
variable? does authorization remain valid? can utilize method prevent connection remain open , utilize firebase normal rest api? to create things little bit more clear:
i not need real-time backend, simple rest backend suffice i utilize firebase because provides easy authentication methods if possible, want avoid using firebase sdk , interact firebase using rest apiin other words question be:
is possible authenticate users client side utilize security rules of firebase while using firebase rest api without using sdk?
this case of extremely premature optimization, , it's detrimental more helpful.
there's no advantage using rest api , sdk in tandem. if have sdk downloaded , have established socket connection, it's going more efficient, cheaper, , less complex re-use existing connection. sdk heavily optimized on rest api , much improve @ dealing temporary disconnections , networking errors. utilizing rest api, you'll making life more hard 0 gain.
if goal download info 1 time without listening updates, utilize once in place of on.
app.controller('ctrl', function($scope) { var ref = new firebase('https://firebase-url.firebaseio.com'); ref.once('value', function(snap) { $scope.data = snap.val(); $scope.apply(); }); });
creating ref() not create connection. first time authenticate, write, or read data, connection established.
authenticating via sdk not help @ rest queries. need pass ?auth=token
url, token auth token create manually (not @ connected sdk simple login auth event).
if don't want real-time capabilities, don't utilize sdk @ all. utilize $http or $resource , connect via .json urls.
angularjs firebase firebase-security firebasesimplelogin
No comments:
Post a Comment