dimanche 26 février 2017

session does not persist after refresh in ember while using torii

I'm using facebook login for my app. I am able to complete login successfully but when i refresh the page session.isAuthenticate becomes undefined. I think the logic to persist the session stays inside fetch method of torii-adapter. Below is my torii-adapter. Please tell me what is missing

import Ember from 'ember';
import {createToken} from 'myapp-new/utils/myapp-utils';
//import User from 'myapp-new/user/model';

export default Ember.Object.extend({
  store: Ember.inject.service(),
  session: Ember.inject.service('session'),
  fetch(){
    let token = session.token;
    if(Ember.isEmpty(token)){
      throw new Error("No session found");
    }
    else{
      return Ember.RSVP.resolve({token});
    }
  },

  open: function(authentication){
    let authorizationCode = authentication.authorizationCode;
    let token = createToken();
    let adapter = this;
    return new Ember.RSVP.Promise(function(resolve, reject){
      console.log(authentication);
      Ember.$.ajax({
        url: 'http://ift.tt/2mANLd8',
       //url:'http://localhost:4200',
        data: { 'code': authorizationCode,token:token},
        success: Ember.run.bind(null, resolve),
        error: Ember.run.bind(null, reject)
      });
    }).then(function(data){
      let user = data.user[0];

      return {
        token:token,
        user: user
      };
    });
  }
});




Aucun commentaire:

Enregistrer un commentaire