mirror of
https://github.com/strapi/strapi.git
synced 2025-12-27 15:13:21 +00:00
Fix/#7197/Change custom populate state to own service (#7204)
* Fix/#7197/Change custom populate state to own service To avoid issue with population we change the service of state user to there own service call "fetchState", also to keep a separate customization Signed-off-by: Juan David <juand.business@gmail.com> * specific service for fetch authenticated user Signed-off-by: Juan David <juand.business@gmail.com> * Update comment Signed-off-by: Juan David <juand.business@gmail.com> * Add some comments Signed-off-by: Juan David <juand.business@gmail.com>
This commit is contained in:
parent
16b91851db
commit
55f576bd1d
@ -16,8 +16,10 @@ 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 });
|
||||
|
||||
// fetch authenticated user
|
||||
ctx.state.user = await strapi.plugins[
|
||||
'users-permissions'
|
||||
].services.user.fetchAuthenticatedUser(id);
|
||||
} catch (err) {
|
||||
return handleErrors(ctx, err, 'unauthorized');
|
||||
}
|
||||
|
||||
@ -61,10 +61,18 @@ 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 authenticated user.
|
||||
* @return {Promise}
|
||||
*/
|
||||
fetchAuthenticatedUser(id) {
|
||||
return strapi.query('user', 'users-permissions').findOne({ id }, ['roles']);
|
||||
},
|
||||
|
||||
/**
|
||||
* Promise to fetch all users.
|
||||
* @return {Promise}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user