Skip to content

Instantly share code, notes, and snippets.

@pollingj
Last active May 1, 2017 07:35
Show Gist options
  • Save pollingj/61e621f4c06c1f475d31 to your computer and use it in GitHub Desktop.
Save pollingj/61e621f4c06c1f475d31 to your computer and use it in GitHub Desktop.
Ember Torri - PhoneGap Facebook Plugin
import Ember from "ember";
export default Ember.Object.extend({
open: function(authentication){
var userId = authentication.userId;
var token = authentication.accessToken;
var store = this.get('store');
return new Ember.RSVP.Promise(function(resolve, reject){
Ember.$.ajax({
type: "POST",
url: window.getURL('/users/sign_in.json'),
data: { 'facebookid': userId, 'token': token },
dataType: 'json',
success: Ember.run.bind(null, resolve),
error: Ember.run.bind(null, reject)
});
}).then(function(user){
localStorage.setItem("auth_token", user.auth_token);
localStorage.setItem("auth_user", user.user.user.id);
var userRecord;
store.filter('user', function(record) {
if (record.get('id') === user.user.user.id) {
return userRecord = record;
}
});
if (!userRecord) {
store.pushPayload('user', user.user);
}
return {
currentUser: store.find('user', user.user.user.id)
};
});
}
});
import Ember from "ember";
export default Ember.Object.extend({
// create a new authorization
open: function(options) {
return new Ember.RSVP.Promise(function(resolve, reject){
facebookConnectPlugin.login(["email", "public_profile"],
function(response) { Ember.run(null, resolve, response.authResponse); },
function(response) { Ember.run(null, reject, response.status); });
}).then(function(response){
return {
userId: response.userID,
accessToken: response.accessToken
}
});
}
});
@v3ss0n
Copy link

v3ss0n commented Oct 19, 2016

does this wtill working with latest ember and torii ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment