Skip to content

Commit

Permalink
Allow custom populate in user model
Browse files Browse the repository at this point in the history
  • Loading branch information
juandl committed Jun 22, 2020
1 parent 9ed11a6 commit 40892ba
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 3 additions & 1 deletion packages/strapi-plugin-users-permissions/services/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ module.exports = {
* @return {Promise}
*/
fetch(params, populate) {
return strapi.query('user', 'users-permissions').findOne(params, populate);
const defaultPopulate = [...populate, 'role'];

return strapi.query('user', 'users-permissions').findOne(params, defaultPopulate);
},

/**
Expand Down

0 comments on commit 40892ba

Please sign in to comment.