Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In the <a href="http://www.embercasts.com/episodes/client-side-authentication-part-2" rel="nofollow">client side authentication of embercasts</a>, have a nice way to handle it:</p> <p>Basically, you have a <code>App.AuthenticatedRoute</code>, where all routes that need authentication will extend. In the <code>beforeModel</code> hook, is checked if the user is authenticated, in that case the presence of the token. If the token isn't present the current transition is stored.</p> <pre><code>App.AuthenticatedRoute = Ember.Route.extend({ ... beforeModel: function(transition) { if (!this.controllerFor('login').get('token')) { this.redirectToLogin(transition); } }, redirectToLogin: function(transition) { alert('You must log in!'); var loginController = this.controllerFor('login'); loginController.set('attemptedTransition', transition); this.transitionTo('login'); } ... }); </code></pre> <p>When the login is performed and valid, the previous transition is take by <code>self.get('attemptedTransition')</code>, and is called <code>retry</code>. This will retry the transition, in the case, the transition where the user attempted go to, before the login authentication redirect:</p> <pre><code>... var attemptedTransition = self.get('attemptedTransition'); if (attemptedTransition) { attemptedTransition.retry(); self.set('attemptedTransition', null); } else { // Redirect to 'articles' by default. self.transitionToRoute('articles'); } ... </code></pre> <p>With this, you will have the same behavior.</p> <p>I hope it helps.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload