【发布时间】:2021-03-12 15:26:55
【问题描述】:
我用它在strapi和nuxt中设置身份验证: Auth with Strapi and Nuxt
我目前正在尝试检索特定于经过身份验证的用户的项目(已签出此strapi - restrict user to fetch only data related to him)。为此,我在 Strapi (/api/routine/config/routes.json) 中创建了一个自定义路由:
{
"method": "GET",
"path": "/routines/me",
"handler": "Routine.me",
"config": {
"policies": []
}
}
和一个自定义控制器 (/api/controllers/Routine.js):
module.exports = {
me: async (ctx) => {
const user = ctx.state.user;
if (!user) {
return ctx.badRequest(null, [{ messages: [{ id: 'No authorization header was found' }] }]);
}
const data = await strapi.services.routine.find({user:user.id});
if(!data){
return ctx.notFound();
}
ctx.send(data);
},
};
我已经通过 Strapi 管理员授予经过身份验证的用户访问“我”的权限。当我从 Nuxt 到达终点时:
const 例程 = await axios.get(
http://localhost:1337/routines/me)
我收到此错误:
GET http://localhost:1337/routines/me 404(未找到)
为什么找不到自定义路由?我是否使用了错误的端点?
【问题讨论】:
标签: authentication routes nuxt.js strapi