I'm trying to get the current user (if logged in) in an Ember.JS app.
I'm following the general approach outlined by @MilkyWayJoe in this post. This entails having a property on the ApplcatinController
like this:
App.ApplicationController = Ember.Controller.extend({
current_user: null,
init: function(){
this.set('current_user', this.store.find("user", "me"));
}
});
Which works fine, loading the current user when the user is logged in. However when the user is not logged in the server (correctly) returns no user. I get the following error in the console:
Assertion failed: You made a request for a user with id me, but the adapter's response did not have any data
Everything still works, but I'd like to avoid having errors pop up in the console.
So I tried working directly with the promise that find
returns:
App.ApplicationController = Ember.Controller.extend({
current_user: null,
init: function(){
var user_promise = this.store.find("user", "me");
var app_controller = this;
user_promise.then(function(user){ //Success
app_controller.set('current_user', user)
}, function(reason){ //Fail
//just resolve the promise, no need to do anything
})
}
});
Which has exactly the same behaviour as the first example: It works, but still prints the same error into the console.
How do I handle the case where the user is not logged in without getting errors in my console?