Skip to content

Instantly share code, notes, and snippets.

@HenrikJoreteg
Created March 9, 2015 21:26
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save HenrikJoreteg/77ced9d8d83ae0435439 to your computer and use it in GitHub Desktop.
Save HenrikJoreteg/77ced9d8d83ae0435439 to your computer and use it in GitHub Desktop.
ampersand router with auth checks
var Router = require('ampersand-router');
var app = require('ampersand-app');
function auth(authLevel, fn) {
return function () {
if (authLevel === 'required' && !app.me.loggedIn) {
this.redirectTo('/login');
return;
}
fn.apply(this, arguments);
};
}
module.exports = Router.extend({
routes: {
'': 'dashboard',
'profile': 'profile',
'login': 'login',
'signup(/:token)': 'signup',
'reset-password(/:token)': 'resetPassword',
'*path': 'fourOhFour'
},
dashboard: auth('required', function () {
app.trigger('page', new Dashboard());
}),
login: function () {
app.trigger('page', new Login());
},
...
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment