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 => {
return {
initialize: function(cb) {
strapi.app.use(async (ctx, next) => {
await next();
_.forEach(strapi.config.routes, value => {
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();
}
};

View File

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