As the title reads, I am having trouble logging into my application after upgrading from Ember 2.x to 3.x (specifically in this case, 2.18.2 to 3.12.1). I tried following this guide : https://github.com/simplabs/ember-simple-auth/blob/master/guides/upgrade-to-v3.md
But it didn't really make sense to me. I tried setting the authenticationRoute
, routeAfterAuthentication
, and routeIfAlreadyAuthenticated
values respectively to the particular routes that my application uses, and as I step through code execution with breakpoints I see that the values are being correctly set, but no dice. None of the other steps there applied to my particular case.
Here are the changes I've made based on the guide --
protected.js (all I did here was add the authenticationRoute
definition) :
import { inject as service } from '@ember/service';
import { isNone } from '@ember/utils';
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
import AutoScrollMixin from 'erm/mixins/auto-scroll';
export default Route.extend(AuthenticatedRouteMixin, AutoScrollMixin, {
authenticationRoute: 'login',
session: service(),
userIdle: service(),
currentUser: service(),
model(/*params, transition*/){
var self = this;
self.get('userIdle').on('idleChanged', (isIdle) => {
if (isIdle) {
self.get('session').invalidate();
self.replaceWith('login');
}
});
if( this.get('session.isAuthenticated') ) {
var user = self.get('currentUser.user');
if( user && user.get('temp_password') ) {
this.transitionTo('change-password');
}
} else {
if( isNone(this.get('session.isAuthenticated')) ||
this.get('session.isAuthenticated') !== true ) {
self.replaceWith('login');
}
}
},
});
application.js (just added the routeAfterAuthentication
entry) :
import { inject as service } from '@ember/service';
import { isNone } from '@ember/utils';
import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin';
export default Route.extend(ApplicationRouteMixin, {
routeAfterAuthentication: 'risks.index',
currentUser: service(),
session: service(),
beforeModel() {
return this._loadCurrentUser();
},
sessionAuthenticated() {
this._super(...arguments);
this._loadCurrentUser();
},
_loadCurrentUser() {
var currUser = this.currentUser;
return isNone(currUser.get('user')) ? currUser.load() : currUser.reload();
}
});
login.js (all I did here was add the routeIfAlreadyAuthenticated
entry) :
import UnauthenticatedRouteMixin from 'ember-simple-auth/mixins/unauthenticated-route-mixin';
export default Route.extend(UnauthenticatedRouteMixin, {
routeIfAlreadyAuthenticated: 'risks.index'
});
Aucun commentaire:
Enregistrer un commentaire