Hey,

Thanks for the reply.
A couple of follow up questions.

1. How do I write to multiple paths with one generic connection (to the
root probably)
2. When you say "work with the Firebase SDK " do you mean the regular JS
functions instead of the AngularFire ones?

Thanks again,
Guy
On Tuesday, October 7, 2014 7:47:43 PM UTC+3, Michael Kato Wulf wrote:

Guy,

When you call Firebase.auth(), you are actually revoking the previous
authentication. Keep in mind that these ops happen asynchronously. So you
fire three authentication events simultaneously, the last one will be
invoked before the first write event takes place.

The reason the last is the only one to succeed is because it is the only
one correctly authenticated. You could verify this by catching/logging the
errors from your $set calls.

Without fully understanding your use case--this looks like a very strange
and probably unnecessary, possibly insecure strategy--I can make several
generic observations:

1) You should probably be calling $scope.token_auth() exactly once and
doing all your sets inside of the single callback. You don't actually have
multiple "connections" here, you're just writing data to multiple paths.

2) AngularFire, $scope, and $asArray may be unnecessary here as nothing
seems to be interacting with the DOM. You could probably run most of this
directly against the Firebase SDK and save some energy downloading data
that you aren't interested in having synchronized locally (keep in mind
that AngularFire is primarily a bindings library and you aren't utilizing
any bindings here).

Hope that helps!

Cheers,
Kato



On Tue, Oct 7, 2014 at 6:59 AM, Guy Tamir <guyt...@gmail.com <javascript:>
wrote:
Hey,

I'm building an app and in one use case I want to write data into several
different locations.
(/messages/userID/, /pending/userID/, /user/userID/messages)

I'm connecting with a token created on my Django server.
I've tried creating a service\factory\simple function that returns a
$firebase object after connecting to a specific path with the token
but if I run 3 commands in the same scope function it only write to
firebase the last command, like for some reason each controller can hold
only one connection
and even though each time the connection is created with
new Firebase(url)

it still doesn't work.

this is what I have:

Token connect function:
$scope.token_auth = function(token,path, callback) {


var url = 'https://#######.firebaseio.com' + path;
var dataRef = new Firebase(url);
dataRef.auth(token, function (error, result) {
if (error)
{
console.log('Login Failed!', error);


}
else
{
var temp = $firebase(dataRef);
callback(temp);
}
});
}


And in the function called from the view that need to write the data:
$scope.send_actual_message = function () {
var token;


$http({url: "../fire_token/",
method: "GET",
params: {'type': 'b'}}).then(function (response) {
console.log(response);
token = response.data.result;


var author = 'b_' + $scope.bid;
var receiver = 'i_' + $scope.in.id;


$scope.token_auth(token,'/messages/' + author + '-' +
receiver + '/',function(data){
console.log(data);
var obj = data;
obj.$set({"brand":author, "influencer" : receiver});
});

$scope.token_auth(token,'/messages/' + author + '-' +
receiver + '/messages',function(data){
var obj = data.$asArray();
obj.$add({'author' : author, 'text' : $scope.text, 'time'
: Firebase.ServerValue.TIMESTAMP});
});


$scope.token_auth(token,'/users/' + receiver + '/messages/',
function(data){
var obj = data;
obj.$set(author, {"author" : author , "text" : $scope.
text, "date" : Firebase.ServerValue.TIMESTAMP}).then(function(ref){
// Setting priority as the latest message
received\sent
ref.$priority = Firebase.ServerValue.TIMESTAMP;
});
});


}, function (err) {
console.log('error');
});
}



And as I said earlier, only the third call is written to firebase

Suggestions regarding a better service\provider\factory option and more
importantly one that allows me multiple connection are needed...

Thanks

--
You received this message because you are subscribed to the Google Groups
"Firebase + AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to firebase-angul...@googlegroups.com <javascript:>.
To post to this group, send email to firebase...@googlegroups.com
<javascript:>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/firebase-angular/722336e1-3ae8-4168-8ca4-b69ec2b91823%40googlegroups.com
<https://groups.google.com/d/msgid/firebase-angular/722336e1-3ae8-4168-8ca4-b69ec2b91823%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Firebase + AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-angular+unsubscribe@googlegroups.com.
To post to this group, send email to firebase-angular@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-angular/33bc97c7-24ef-4cd0-a8a8-7c7d9a5de99e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Previous

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 3 of 3 | next ›
Discussion Overview
groupfirebase-angular @
postedOct 7, '14 at 1:59p
activeOct 8, '14 at 8:21a
posts3
users2

2 users in discussion

Guy Tamir: 2 posts Michael Wulf: 1 post

People

Translate

site design / logo © 2021 Grokbase