mardi 24 février 2015

Ember CLI Simple Auth's custom session for a Rails API depends on Rails' session cookie

I'm using Ember CLI 0.1.15 with Ember-CLI-Simple-Auth-Addon 0.7.3 + Devise plugin to authenticate my app against a Rails 4.2 backend with gem Devise 3.4.1. My configuration is pretty much like http://ift.tt/1DORwl5 and works fine.


However, once I introduce a custom session for Ember-CLI-Simple-Auth my session is not persisted anymore: the post request for the login in is succesful, but the very next get request GET "/api/users/1" is answered with Completed 401 Unauthorized. I am then back at the index:route. I can make the session work by changing in my Rails app's session_store.rb the line



Rails.application.config.session_store :disabled


to



Rails.application.config.session_store :cookie_store, key: '_test_app_session'


Thus, that session introduces a depency for being authorized by a Rails' session cookie. But why?


This is my Ember-app's custom session (app\initializers\custom-session.js):



import Ember from 'ember';
import Session from 'simple-auth/session';

export function initialize(container) {
var CustomSession = Session.extend({
currentUser: function() {
var userId = this.get('user_id');
if (!Ember.isEmpty(userId)) {
return this.container.lookup('store:main').find('user', userId);
}
}.property('userId')
});
container.register('session:custom', CustomSession);
}

export default {
name: 'custom-session',
before: 'simple-auth',
initialize: initialize
};


It is then called in my environment.js via:



ENV['simple-auth'] = {
authorizer: 'simple-auth-authorizer:devise',
session: 'session:custom'
}




Aucun commentaire:

Enregistrer un commentaire