import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin';

The mixin for the application route; defines methods that are called when the session was 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.container.lookup('route:application');
            const session          = instance.container.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

source public

sessionAuthenticated( )

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, this action transitions to the routeAfterAuthentication.

source public

sessionInvalidated( )

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.

Properties

source public

routeAfterAuthentication: String

Default: 'index'

The route to transition to after successful authentication.

source public readonly

session: SessionService

The session service.