Created
December 1, 2015 20:16
-
-
Save barelyknown/bf7bd42bd865fc446702 to your computer and use it in GitHub Desktop.
authenticate-in-ember-using-a-url-parameter-3.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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