ember-simple-auth: Session service not instantiated in Fastboot
I have just upgraded to master and started integrating ember-simple-auth with fastboot, switching to Cookie session store from Adaptive as instructed.
However the session’s state doesn’t seem to be instantiated on the server. While ember_simple_auth-session cookie is present with all the necessary data, the session.isAuthenticated still returns false and session.data is empty in fastboot mode:
// /app/routes/application.js
import Ember from 'ember';
import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin';
export default Ember.Route.extend(ApplicationRouteMixin, {
currentUser: Ember.inject.service(),
fastboot: Ember.inject.service(),
beforeModel() {
// Cookie is present:
Ember.Logger.log('cookies', this.get('fastboot.request.cookies'));
// => { 'ember_simple_auth-session': '{"authenticated":{"authenticator":"authenticator:devise","token":"XhIJ...","email":"...@...com"}}' }
// But session is not restored from cookie:
Ember.Logger.log('session.data', this.get('session.data'));
// => { authenticated: {} } {}
Ember.Logger.log('session.isAuthenticated', this.get('session.isAuthenticated'));
// => false
return this._loadCurrentUser();
},
_loadCurrentUser() { return this.get('currentUser').load(); },
sessionAuthenticated() {
this._loadCurrentUser().then(() => {
if (this.get('session.data.redirectUrl')) {
var redirectUrl = this.get('session.data.redirectUrl');
this.get('session').set('data.redirectUrl', null);
window.location.replace(redirectUrl);
}
}).catch(() => this.get('session').invalidate() );
},
});
On the frontend the same code works as expected returning true for session.isAuthenticated and restoring session.data from cookie.
Not sure if I’m doing something wrong, or if this is a bug.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 20 (19 by maintainers)
I’ve figured it. The OAuth2 Password Grant Authenticator imports
ember-network/fetch. This usesnode-fetchwhich needs to be whitelisted in thefastbootDependenciesarray inpackage.json, otherwise it gets rejected.I only discovered this by using Node debugger and following the stack trace through. No exception was thrown in the console.