I’m trying to add a policy to a route defined in a plugin in order to test it via API call rather than triggering with a cron-job. I can sidestep the issue by adding “auth: false”, but I want it to be limited to authenticated users.
I have a policy defined
module.exports = async (ctx, next) => {
if (ctx.state.user) {
// go to next policy or will reach the controller's action.
return await next();
}
ctx.unauthorized(`You're not logged in!`);
};
exported in a policies/index.js file
const isAuthenticated = require('./is-authenticated');
module.exports = {
isAuthenticated,
};
and in /routes/index.js
module.exports = [
{
method: 'GET',
path: '/notifications/baseline-increase',
handler: 'notification.sendBaselineIncrease',
config: {
policies: ['plugins::notifications-plugibn.isAuthenticated'],
middlewares: [],
prefix: ""
},
},
{
method: 'GET',
path: '/notifications/exercises-not-started',
handler: 'notification.sendExercisesNotStarted',
config: {
policies: [],
middlewares: [],
},
}
];
];
“‘plugins::users-permissions.isAuthenticated’” also doesn’t work for some reason. In both cases I get a “cannot find policy” error
This topic has been created from a Discord post (1283032638852038799) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord