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