torii facebook ember get user and name - ember.js

Hi I want to get name and email from facebook authentication via torii and simple-auth, but I don't know how recovery this data. I can login via facebook but I can't get name or email.
Could you helpme please
This is my code:
//import Base from 'ember-simple-auth/authenticators/base';
import Ember from 'ember';
import ToriiAuthenticator from 'ember-simple-auth/authenticators/torii';
export default ToriiAuthenticator.extend({
torii: Ember.inject.service()
});
This is my component login-form
import Ember from 'ember';
export default Ember.Component.extend({
actions:{
facebookLogin(){
this.get('session').authenticate('authenticator:torii', 'facebook-oauth2').then((data)=>{
alert("logueado" + data);
});
}
}
});
And my torii-provider
// app/torii-providers/facebook.js
import FacebookOauth2Provider from 'torii/providers/facebook-oauth2';
export default FacebookOauth2Provider.extend({
fetch(data) {
return data;
}
});

Related

How setup an adapter to return data from an API for my application route in Ember data?

I'm learning to use ember data. I want to build an image searching app using Pixabay's free API.
I want to send search queries to adapter and get the results in route via model. First of all, I'm not sure how to create adapter for application route. I found many tutorials on ember data, they all built adapters and model for a specific model not on the application route.
app/routes/application.js
import Route from '#ember/routing/route';
export default Route.extend({
model(){
return this.store.findAll('application');
}
});
app/models/application.js
import DS from 'ember-data';
import Model from 'ember-data/model'
const { attr } = DS;
export default Model.extend({
largeImageURL : attr('string')
});
app/adapters/application.js
import DS from 'ember-data';
export default DS.JSONAPIAdapter.extend({
host:"https://pixabay.com/api/?key=<API-KEY>&q=<queries>",
pathForType(){
return '/';
}
});

Trying to get data with ember and django rest framework

I have installed Ember Django Adapter(EDA) and I have followed the tutorial and in the template everything is ok but I'm not getting data from my api... but when my model its connect to the api I get the following warning in the console.
WARNING: Encountered "articles" in payload, but no model was found for model name "article" (resolved model name using frontend#serializer:articles:.modelNameFromPayloadKey("articles"))
This is my code:
app/application/serializer.js
import DRFSerializer from '../serializers/drf';
export default DRFSerializer.extend({
});
app/application/adapter.js
import DRFAdapter from '../adapters/drf';
import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin';
export default DRFAdapter.extend(DataAdapterMixin , {
authorizer: 'authorizer:django'
});
app/router.js
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: config.locationType
});
Router.map(function() {
this.route('index');
});
export default Router;
app/models/articles.js
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
export default Model.extend({
title: attr('string'),
body: attr('string')
});
app/index/route.js
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.get('store').findAll('articles');
}
});
app/index/template.hbs
{{#each model as |article|}}
<article class="listing">
<h3>{{article.title}}</h3>
</article>
{{/each}}
You should use singular words when naming models, so change your model file to "article.js" and also change in route.js file to this.get('store').findAll('article');

Requests to different backend endpoint from same route and save the result in different model

I have a designed a app in ember.Now the app has feed page similar to fb and instagram.Now to get the username and his display pic, I have to send the request to "http://example.com/api/users/profile/?targetuser=-1" and the to get the user feed I have to make the requests to "http://example.com/api/feed".I am not able to figure out how to do it.
routes.js
import Ember from 'ember';
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
export default Ember.Route.extend(AuthenticatedRouteMixin,{
model(){
return Ember.$.ajax({
url: 'http://example.com/api/users/profile/?targetuser=-1',
headers:{
"Authorization":"token b0"
},
success:function(user_details)
{
console.log(user_details.full_name);
}
});
},
model(){
var inflector = Ember.Inflector.inflector;
inflector.uncountable('feed');
return this.store.findRecord('feed');
}
});
But in this case request is made only to "http://example.com/api/feed" and the ajax call is left.
I also want to store the data from both call to different store ,So that I can use it in hbs.
my models
feed.js
import DS from 'ember-data';
export default DS.Model.extend({
FeedResult: DS.attr(),
// gallery_name:DS.attr(),
// feedPhotos:DS.attr()
});
profile.js
import DS from 'ember-data';
export default DS.Model.extend({
results: DS.attr(),
photos:DS.attr()
});
Please suggest how should I do this so I can display the username,display pic and his feed on same page just like fb and instagram.

how to use another controller method in ember

im' trying to use a method which is in application.js, is these a controller.
it has a method called isAuthenticated which return if a user is login or not.
in my application.hbs it works fine,
but when i call it in my posts/new.hbs it always return false.
why it?
my application controller,
import Ember from 'ember';
import App from '../app';
export default Ember.Controller.extend({
authManager: App.AuthManager,
currentUser: function() {
return App.AuthManager.get('apiKey.user');
}.property('authManager.apiKey'),
isAuthenticated: function() {
return App.AuthManager.isAuthenticated();
}.property('authManager.apiKey'),
});
solutions?

ember.js: Make AdminRouteMixin from AuthenticatedRouteMixin?

Is there a more elegant way to prevent unauthorized access to an admin-only route than writing this in all of my admin routes?
export default Ember.Route.extend(AuthenticatedRouteMixin, {
beforeModel: function(){
if(!this.get('session.secure.admin')) this.transitionTo("dashboard");
}
});
Perhaps it's possible to extend AuthenticatedRouteMixin itself to make this kind of check?
Thanks!
Why not just make the mixin?
import Ember from 'ember';
import AuthenticatedRouteMixin from 'wherever/it/is'.
const { Mixin } = Ember;
export default Mixin.create(AuthenticatedRouteMixin, {
beforeModel(){
if(!this.get('session.secure.admin')) {
this.transitionTo("dashboard");
}
}
})
And then import it in your routes:
import Ember from 'ember';
import AdminCheckMixin from 'yourApp/mixins/routes/admin-check';
const { Route } = Ember;
export default Route.extend(AdminCheckMixin);