ApplicationRouteMixin
import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin';
Deprecated:Call the session service's setup method in the application route's constructor instead
The mixin for the application route, defining methods that are called when the session is successfully authenticated (see authenticationSucceeded) or invalidated (see invalidationSucceeded).
Using this mixin is optional. The session events can also be handled manually, e.g. in an instance initializer:
// app/instance-initializers/session-events.js
export function initialize(instance) {
const applicationRoute = instance.lookup('route:application');
const session = instance.lookup('service:session');
session.on('authenticationSucceeded', function() {
applicationRoute.transitionTo('index');
});
session.on('invalidationSucceeded', function() {
applicationRoute.transitionTo('bye');
});
};
export default {
initialize,
name: 'session-events',
after: 'ember-simple-auth'
};
When using the ApplicationRouteMixin
you need to specify
needs: ['service:session']
in the application route's unit test.
Methods
This method handles the session's
authenticationSucceeded
event. If there is a transition that was previously intercepted by the
AuthenticatedRouteMixin's beforeModel
method it will retry
it. If there is no such transition, the ember_simple_auth-redirectTarget
cookie will be checked for a url that represents an attemptedTransition
that was aborted in Fastboot mode, otherwise this action transitions to the
AuthenticatedRouteMixin/routeAfterAuthentication:property.
This method handles the session's invalidationSucceeded event. It reloads the Ember.js application by redirecting the browser to the application's root URL so that all in-memory data (such as Ember Data stores etc.) gets cleared.
If the Ember.js application will be used in an environment where the users don't have direct access to any data stored on the client (e.g. cordova) this action can be overridden to e.g. simply transition to the index route.