Closed crdil closed 8 years ago
I'm using connect-roles with passportjs and express. For now my code (snippets of it) looks like this..
// roles.js import connectRoles from 'connect-roles'; export const roles = new connectRoles(); // routes.js import { roles } from '../libs/roles'; ... ... roles.use((req, action) => { if (!req.isAuthenticated()) return action === 'access home page'; }); roles.use('access admin page', (req, action) => { if (req.user.role === 'admin') { return true; } }); .get(passport.authenticate('jwt', { session: false }), roles.can('access admin page'), controller.TestController.getTest); // app.js ... ... import { roles } from '../libs/roles'; app.use(roles.middleware());
But since I want to be able to use the same rules on other routes then the ones in routes.js I need to put them into a module, but I'm not sure how I can do that. If anyone can point me in the right direction I would really appreciate that.
Thanks
Nevermind, got it sorted
Hi @crdil , can you tell please how you solve this ?
I'm using connect-roles with passportjs and express. For now my code (snippets of it) looks like this..
But since I want to be able to use the same rules on other routes then the ones in routes.js I need to put them into a module, but I'm not sure how I can do that. If anyone can point me in the right direction I would really appreciate that.
Thanks