Inject authentication policy

This commit is contained in:
Jim Laurie 2017-11-27 10:59:24 +01:00
parent a2c8e212fc
commit 9a801e4ac1
3 changed files with 20 additions and 3 deletions

View File

@ -0,0 +1,5 @@
module.exports = async (ctx, next) => {
const config = strapi.plugins['users-permissions'].config;
await next();
};

View File

@ -1,10 +1,21 @@
const pathToRegexp = require('path-to-regexp');
const _ = require('lodash');
module.exports = strapi => { module.exports = strapi => {
return { return {
initialize: function(cb) { initialize: function(cb) {
strapi.app.use(async (ctx, next) => { _.forEach(strapi.config.routes, value => {
await next(); value.config.policies.unshift('plugins.users-permissions.isAuthenticated');
}); });
if (strapi.plugins) {
_.forEach(strapi.plugins, (plugin, name) => {
_.forEach(plugin.config.routes, value => {
value.config.policies.unshift('plugins.users-permissions.isAuthenticated');
});
});
}
cb(); cb();
} }
}; };

View File

@ -26,6 +26,7 @@
"dependencies": { "dependencies": {
"bcryptjs": "^2.4.3", "bcryptjs": "^2.4.3",
"jsonwebtoken": "^8.1.0", "jsonwebtoken": "^8.1.0",
"path-to-regexp": "^2.1.0",
"sendmail": "^1.2.0", "sendmail": "^1.2.0",
"strapi-helper-plugin": "3.0.0-alpha.6.7" "strapi-helper-plugin": "3.0.0-alpha.6.7"
}, },