I am seeking an efficient way to achieve my flow of events. So far this is what I am trying to do:
I have an object that is the result of a Meteor.call(...function, (error, result))
I declare the object on my client myObject = result This call takes place when a user clicks a button
Now, how can I put this variable into another meteor call that I am now making within a Router.route (Iron router)? As of now, it is undefined.
The values within this object are already defined on the server within a function. I am really passing this object from the server,to the client, and back around to the server again. Can I store it on the server to be used in other function?
I read that storing global variables on the server can mess things up for other user when they set values to these variables. Is this correct?
e.g. the next call but the myObject is undefined
Router.route('/home/', {
name: 'home',
waitOn: function () {
},
action: function () {
// putting 'myObject' into call to pass onto the server
Meteor.call('toUseTheObjectOnServer', myObject, function (error, response) {
if (error) {
console.log(error)
} else {
console.log(response)
}
})
}
if (this.ready())
this.render('home');
else
this.render('Loading');
}
});
my flow of events to achieve:
(server) http post - I have 2 fields (token, token_secret) returned within the body. callback returns the result to the client
(client) I use one of the fields 'token' to construct a url and direct the user to this as soon as I get the result. The user signs into the external app, effectively granting me access to their data.
If the user grants me access, the user is directed to the callback url I have provided to the service provider. The service provider adds a parameter to this callback url which indicates if the user granted me access. The parameter in the callback url is authorize=1...this means i have been granted. authorize=0... I have not been granted access.
- (server) If I have been granted access, I then need to make another http call on server using the token and token_secret values from step 1. which are now 'authorised' values. The response in the body are 'access tokens' that I store in my database in order to make authorised api calls for whatever data I want.