I am currently developing an Ember.js application which fetches data from Facebook.
The problem I have is that I actually have no idea how access the data which was fetched in the application route in my component (js/hbs).
My application route currently looks like this:
import Ember from 'ember';
import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin'
export default Ember.Route.extend(ApplicationRouteMixin, {
fetchCurrentUser() {
const data = this.get('session.data.authenticated');
const {accessToken} = data;
if (accessToken) {
return new Promise(resolve => {
FB.api('/me?fields=name,posts&access_token=' + accessToken, response => {
resolve()
})
})
}
},
beforeModel(transition) {
this._super(transition);
if (this.get('session.isAuthenticated')) {
return this.fetchCurrentUser()
}
},
actions: {
login() {
return this
.get('session')
.authenticate('authenticator:torii', 'facebook-connect')
.then(() => {
this.fetchCurrentUser();
})
.catch(err => console.error(err));
},
logout() {
return this
.get('session')
.invalidate()
}
}
});
I have already searched for an approach but most of the information is outdated.
Does anyone have a suggestion for me?
Aucun commentaire:
Enregistrer un commentaire