javascript - How do I transition to a root on successful sign in using Ember-Auth? -


so have implemented ember-auth using pure token based approach. redirect user root of app once sign in.

i know can use actionredirectable (http://ember-auth.herokuapp.com/docs in docs) since using pure token approach , not storing in cookies signing user in again every time page refreshes using remember_token (which seems unideal i'll work out shortly). means using actionredireactable mean redirecting every time user refreshes page. perhaps there anti-pattern in there somewhere?

anyway here signinview:

app.signinview = ember.view.extend({    templatename: 'auth/sign_in',    email:    null,   password: null,    submit: function(event, view) {     event.preventdefault();     event.stoppropagation();      app.auth.signin({       data: {         email:    this.get('email'),         password: this.get('password')       }     });   } }); 

if call this.get("controller").transitiontoroute('...') directly after signin call user invariably isn't signed in point redirected login page again. , if try:

app.auth.on('signinsuccess', function() {   // ... }); 

then don't have sensible way access router transition. bright ideas appreciated. thanks!

as best practice should not have logic in view, logic better suited live in controllers, use case, create app.signincontroller instrument there authentication process:

view

app.signinview = ember.view.extend({   templatename: 'auth/sign_in',   email:    null,   password: null,    submit: function(event, view) {     event.preventdefault();     event.stoppropagation();      var data = {         email:    this.get('email'),         password: this.get('password')     }     // forward action controller passing along     // data object sign in process needs     this.get("controller").send("signin", data);   } }); 

furthermore, should not transitionto elsewhere other inside router. doing so, run serious issues because don't know in state router is. best thing reference router , call transitionto on router instead:

controller

app.signincontroller = ember.objectcontroller.extend({   signin: function(data) {      // grab passed data object , issues sign in     app.auth.signin({       data: data     });      // subscribe `signinsuccess` event ,      // transition route using      // router     app.auth.one('signinsuccess', function() {       var router = this.get('target.router');       router.transitionto('route_name');     });    } }); 

hope helps.


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -