System Information
- Strapi Version: 4.25.1
- Operating System: Ubuntu 23.10
- Database: SQLITE
- Node Version: 18.19.0
- NPM Version: 10.8.1
Hey guys I’ve got a strapi app in development which I haven’t touched in a while. So today I decided I wanted to work a little on it and updated strapi to v4.25.1 (from 4.8.1).
Now I’ve encountered the first problem; somehow the user sanitization changed. I’ve got a dashboard to which the user gets redirected after login, and some relations are populated and in the end the user entity is sanitized (we wouldn’t want those password hashes to leak…).
But I can’t get this to work. What I’ve got so far is:
currentUser: async(ctx, next) => {
const { id, isAdmin = false } = await strapi.plugins['users-permissions'].services.jwt.getToken(ctx);
const user = await strapi.entityService.findOne('plugin::users-permissions.user', id, {
populate: ['relation_1', 'relation_1.images', 'relation_1.ratings'],
});
const userWithRelated = await strapi.query('plugin::users-permissions.user').findMany({
where: {
id: {
$eq: id
}
},
populate: {
relation_1: {
populate: {
images: {},
relation_2: {
populate: {},
filter: {
user
},
where: {
users_permissions_user: {
id: {
$eq: id
}
}
}
},
relation_3: {
filter: {
user
},
where: {
user: {
id: {
$eq: id
}
}
}
}
}
}
}
});
const contentType = strapi.contentType('plugin::users-permissions.user');
await validate.contentAPI.query(ctx.query, contentType, {
auth: ctx.state.auth,
})
let userWithRelatedSanitized = await this.sanitize.contentAPI.output(userWithRelated, 'plugin::users-permissions.user');
return userWithRelatedSanitized;
}
Which leaves me with an exception Cannot read properties of undefined (reading 'contentAPI')
. But from what I’ve read in the docs, this should be the correct way (Controllers | Strapi Documentation).
What am I missing here? Any help would be greatly appreciated.
Best regards
derelektrischemoench