Search code examples
ember.jsember-simple-auth

With Ember Simple Auth, how do I redirect to a login page if user is on a page they need to be signed in to view?


When using Ember Simple Auth, how do I redirect the user to a login page if they are trying to view a page they can only access when they are signed in?


Solution

  • You just must import AuthenticatedRouteMixin in your Route

    import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
    

    and use it like this:

    export default Ember.Route.extend(AuthenticatedRouteMixin);
    

    This will make the route (and all of its subroutes) transition to a configurable login route when the session is not authenticated.

    More info here.