This addon provides a mu-login and mu-logout component for the mu-login microservice. The addon is based on ember-simple-auth.
ember install ember-mu-login
Just include the {{mu-login}}
or {{mu-logout}}
component in your template.
To overwrite the template of the components, create a custom mu-login.hbs
or mu-logout.hbs
file. Make sure you use the correct bindings and actions. You can have a look at the default templates in addon/templates/components
.
For mu-login
- call the
login
action - use
nickname
andpassword
as value bindings for the input fields
For mu-logout
- call the
logout
action
To customize the components, generate your own new components and include the mu-login (ember-mu-login/mixins/mu-login
) and mu-logout (ember-mu-login/mixins/mu-logout
) mixins to handle the login
and logout
actions.
The ember-mu-login addon is based on ember-simple-auth. The following paragraphs highlight the features you will probably need in combination with ember-mu-login. A complete usage and configuration guide can be found in the ember-simple-auth documentation.
You can use ember-simple-auth's isAuthenticated
property to check the current session's state. The session service needs to be injected.
// app/controllers/application.js
import Ember from 'ember';
export default Ember.Controller.extend({
session: Ember.inject.service('session')
…
});
Mix the ApplicationRouteMixin
into the application route to have the authenticationSucceeded
and invalidationSucceeded
events handled automatically:
// app/routes/application.js
import Ember from 'ember';
import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin';
export default Ember.Route.extend(ApplicationRouteMixin);
To make a route in the application accessible only when the session is authenticated, mix the
AuthenticatedRouteMixin
into the respective route:
// app/routes/protected.js
import Ember from 'ember';
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
export default Ember.Route.extend(AuthenticatedRouteMixin);
This will make the route (and all of its subroutes) transition to the login
route if the session is not authenticated.