I have my node server that return me the information on the user every time I'm doing a get request on /session.
I wanted to verified the session in the beforeModel on one of my route, if the session was setup so I just let the user to load the model, otherwise I sending him at the login page with my transitiontoroute, but it doesn't seems to work..
I've got the correct answer from the server, but I can't figure it out how to work with it.
App.HomeRoute = Ember.Route.extend({
beforeModel: function() {
if (this.isSession() == true) {
console.log('OK continue');
}
else {
console.log('GTFO');
this.transitionToRoute('login');
}
},
model: function() {
return this.store.all('user');
},
isSession: function() {
$.ajax({
url: host + 'mdf/session',
type: 'GET',
accepts: 'application/json',
success: function(data) {
console.log('DEBUG: GET Session OK');
return true;
},
error: function() {
console.log('DEBUG: GET Session Failed');
return false;
}
});
}
});
I have this error when I'm trying to go to my /home without login before with the GTFO log.
Error while loading route: TypeError: Object [object Object] has no method 'transitionToRoute'
The problem is that I also have the GTFO message when I log in... I've check the return of my isSession and it 'undefined' ?!?
But I've the log as well that say I've got my session OK..
I'm kinda lost into this...