Skip to content

Instantly share code, notes, and snippets.

@Bondifrench
Created March 11, 2016 20:39
Show Gist options
  • Save Bondifrench/71ae3d3214da26422313 to your computer and use it in GitHub Desktop.
Save Bondifrench/71ae3d3214da26422313 to your computer and use it in GitHub Desktop.
function auth(component) {
return {
controller: function () {
var ctrl = this;
function success(user) {
Account.user(user)
ctrl.output = new component.controller()
m.redraw(true)
}
function failure(err) {
m.route('/login')
}
if (!Account.user()) {
Account.identity().then(success, failure)
} else {
success(Account.user())
}
},
view: function (ctrl) {
return ctrl.output
? component.view(ctrl.output)
: { subtree: 'retain' }
}
}
}
@Bondifrench
Copy link
Author

Mithril authorisation with component logic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment