I have created customization in my controllers. A “me” method,
// Get logged in users
async me(ctx) {
const user = ctx.state.user;
if (!user) {
return ctx.badRequest(null, [
{ messages: [{ id: "No authorization header was found" }] },
]);
}
const data = await strapi.services.learner.find({ user: user.id });
if (!data) {
return ctx.notFound();
}
return sanitizeEntity(data, { model: strapi.models.learner });
},
};
And I created a new route in my config:
{
"method": "GET",
"path": "/learners/me",
"handler": "learner.me",
"config": {
"policies": []
}
},
I’m trying to fetch with Next:
export async function getServerSideProps({ req }) {
const { token } = parseCookies(req)
const res = await fetch(`${API_URL}/learners/me`, {
method: 'GET',
headers: {
Authorization: `Bearer ${token}`,
},
})
const student = await res.json()
return {
props: {
student,
token,
},
}
}
But I’m getting a bad request error:
- error: “Bad Request”
- message: “Your filters contain a field ‘user’ that doesn’t appear on your model definition nor its relations”
- statusCode: 400