Skip to content

Commit

Permalink
Fix/#7197/Change custom populate state to own service
Browse files Browse the repository at this point in the history
To avoid issue with population we change the service of state user to there own service call "fetchState", also to keep a separate customization
  • Loading branch information
juandl committed Jul 27, 2020
1 parent e81c6ba commit 57f3f00
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ module.exports = async (ctx, next) => {
throw new Error('Invalid token: Token did not contain required fields');
}

ctx.state.user = await strapi.plugins['users-permissions'].services.user.fetch({ id });

ctx.state.user = await strapi.plugins['users-permissions'].services.user.fetchState({ id });
} catch (err) {
return handleErrors(ctx, err, 'unauthorized');
}
Expand Down
10 changes: 9 additions & 1 deletion packages/strapi-plugin-users-permissions/services/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,15 @@ module.exports = {
* Promise to fetch a/an user.
* @return {Promise}
*/
fetch(params, populate = ['role']) {
fetch(params, populate) {
return strapi.query('user', 'users-permissions').findOne(params, populate);
},

/**
* Promise to fetch state user in header.
* @return {Promise}
*/
fetchState(params, populate = ['role']) {
return strapi.query('user', 'users-permissions').findOne(params, populate);
},

Expand Down

0 comments on commit 57f3f00

Please sign in to comment.