Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barelyknown/bf7bd42bd865fc446702 to your computer and use it in GitHub Desktop.
Save barelyknown/bf7bd42bd865fc446702 to your computer and use it in GitHub Desktop.
authenticate-in-ember-using-a-url-parameter-3.js
// app/routes/application.js
import Ember from 'ember';
import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin';
export default Ember.Route.extend(ApplicationRouteMixin, {
session: Ember.inject.service('session'),
isTokenAuthenticating: null,
model(params) {
const { token } = params;
if (token) {
this.set('isTokenAuthenticating', true);
if (this.get('session.isAuthenticated')) {
this.get('session').invalidate();
}
return this.get('session').authenticate('authenticator:token', token);
} else {
if (!this.get('session.isAuthenticated')) {
this.transitionTo('login');
}
}
},
sessionAuthenticated() {
if (!this.get('isTokenAuthenticating')) {
this.transitionTo('authenticated');
} else {
this.set('isTokenAuthenticating', false);
}
},
sessionInvalidated() {
if (!this.get('isTokenAuthenticating')) {
this._super();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment