mirror of
https://github.com/strapi/strapi.git
synced 2025-11-01 18:33:55 +00:00
Allow custom populate in ctx.state.user (#6770)
* Allow custom populate in user model Signed-off-by: Juan David <juand.business@gmail.com> * use merge from lodash to join a custom populate Signed-off-by: Juan David <juand.business@gmail.com> * refactor fech
This commit is contained in:
parent
66637e0101
commit
f4959d9560
@ -16,7 +16,7 @@ module.exports = async (ctx, next) => {
|
||||
if (isAdmin) {
|
||||
ctx.state.admin = await strapi.query('administrator', 'admin').findOne({ id }, []);
|
||||
} else {
|
||||
ctx.state.user = await strapi.query('user', 'users-permissions').findOne({ id }, ['role']);
|
||||
ctx.state.user = await strapi.plugins['users-permissions'].services.user.fetch({ id });
|
||||
}
|
||||
} catch (err) {
|
||||
return handleErrors(ctx, err, 'unauthorized');
|
||||
|
||||
@ -62,7 +62,7 @@ module.exports = {
|
||||
* Promise to fetch a/an user.
|
||||
* @return {Promise}
|
||||
*/
|
||||
fetch(params, populate) {
|
||||
fetch(params, populate = ['role']) {
|
||||
return strapi.query('user', 'users-permissions').findOne(params, populate);
|
||||
},
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user