Skip to content

Instantly share code, notes, and snippets.

@mauritslamers
Created April 24, 2014 20:49
Show Gist options
  • Save mauritslamers/11269026 to your computer and use it in GitHub Desktop.
Save mauritslamers/11269026 to your computer and use it in GitHub Desktop.
auth check statechart
myApp.statechart = SC.Statechart.create({
rootState: SC.State.design({
initialSubstate: 'CHECKAUTH',
CHECKAUTH: SC.State.design({
enterState: function () {
SC.Request.getUrl('/auth/is-authenticated').notify(this, '_authcheckDidRespond').send();
},
_authcheckDidRespond: function (result) {
if (SC.ok(result)) {
// let's assume that the auth is ok here
this.gotoState('HASAUTH');
}
else {
this.gotoState('HASNOAUTH');
}
}
}),
HASAUTH: SC.State.design({
enterState: function () {
// continue into the app
}
}),
HASNOAUTH: SC.State.design({
enterState: function () {
// show some login screen...
}
})
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment