0

Login form in my app is realized via hidden form (which overlays the page and is displayed through data-toggle).

It is nice and user friendly, however the problem occurs when unauthenticated user wants to access protected route - Ember Simple Auth wants to redirect to /login. How to display login form in that case?

yaqwsx
  • 569
  • 1
  • 5
  • 14

1 Answers1

1

It's easy - in your application route override an sessionRequiresAuthentication action. This action is defined in application-route-mixin, and by default looks like:

sessionRequiresAuthentication: function() {
  this.transitionTo(Configuration.authenticationRoute);
},

Instead of transitioning you may write a code to open a login form

Gennady Dogaev
  • 5,902
  • 1
  • 15
  • 23
  • But in this action I have to transit somewhere, haven't I? When the user enters the routes url, nothing is rendered yet and the login form isn't put in DOM yet. – yaqwsx Sep 22 '15 at 15:11
  • 1
    If some route was rendered before, user will stay at that route and login form should be available. But, if user comes to forbidden route directly, you should redirect them somewhere. – Gennady Dogaev Sep 22 '15 at 16:05
  • If I override the handling just to do nothing and than I try to access protected route, I get `Error while processing route: about transition is undefined`. – yaqwsx Sep 22 '15 at 16:21
  • Ok, maybe I have a better question: How can i tell in the sessionRequiresAuthentication if I am on a blank page or if another route is active or which route was meant to be accessed? – yaqwsx Sep 22 '15 at 16:52
  • Which route is meant to be accessed: `var attemptedTransition = this.get('session').get('attemptedTransition'); var route = attemptedTransition.targetName;`. Use console.log to inspect `transition` object, it contains some other info about route, that user tried access to. This answer http://stackoverflow.com/questions/18302463/get-current-route-name-in-ember may (or may not) help to determine if other route was active before. – Gennady Dogaev Sep 22 '15 at 18:23