2026-07-04 10:04:00 +04:00
|
|
|
'use strict';
|
|
|
|
|
|
2026-07-04 20:00:51 +04:00
|
|
|
const { UnauthorizedError } = require('@strapi/utils').errors;
|
2026-07-04 10:04:00 +04:00
|
|
|
|
|
|
|
|
module.exports = async (policyContext, config, {strapi}) => {
|
2026-07-04 20:00:51 +04:00
|
|
|
const {request} = policyContext;
|
2026-07-04 10:04:00 +04:00
|
|
|
|
|
|
|
|
if (!request?.header?.authorization) {
|
2026-07-04 20:00:51 +04:00
|
|
|
throw new UnauthorizedError('Opération non autorisée');
|
2026-07-04 10:04:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
2026-07-04 20:00:51 +04:00
|
|
|
const {id} = await strapi.plugins['users-permissions'].services.jwt.getToken(policyContext);
|
2026-07-04 10:04:00 +04:00
|
|
|
|
|
|
|
|
if (id !== request.body?.data?.user?.id) {
|
2026-07-04 20:00:51 +04:00
|
|
|
throw new UnauthorizedError('Opération non autorisée');
|
2026-07-04 10:04:00 +04:00
|
|
|
}
|
|
|
|
|
} catch (err) {
|
2026-07-04 20:00:51 +04:00
|
|
|
throw new UnauthorizedError('Opération non autorisée');
|
2026-07-04 10:04:00 +04:00
|
|
|
}
|
|
|
|
|
|
2026-07-04 20:00:51 +04:00
|
|
|
return true;
|
|
|
|
|
};
|