When my app boots I want to go off to an authenticated URl to fetch the current user info. If the URl returns unauthorized then I will know the user is logged out.
To do this I have an initializer which halts progression:
export var initialize = function(container, app) {
app.deferReadiness();
Sonatribe.Ajax.ajax('model/useraccount/')
.then(function(result){
var store = container.lookup('store:main');
var user = store.createRecord('user', result.result);
app.advanceReadiness();
return user;
});
};
export default {
name: 'initialize-user',
initialize: initialize
};
And to test this I have a link to the users profile:
{{#link-to 'user-profile' currentUser}}profile{{/link-to}}
Now, given I am logged in so the URL returns the JSON and I can see that once it returns - there is infact a user model in the ember inspector. The link just uses # - so it looks like it was created before the promise returned. Which is confusing and annoying because i am halting progression until the promise completes.
Am I missing something? Is there a better way to do this?
I can see that in discourse they are preloading a store with JSON - we can’t do this ATM because we haven’t figured out how to embed ember into an app like ruby or serviecstack c# MVC