refactor: extraire la vérification JWT/payload en policy partagée
This commit is contained in:
@@ -12,20 +12,6 @@ module.exports = createCoreController('api::artiste.artiste', ({strapi}) => ({
|
||||
const {body} = ctx.request
|
||||
let {data} = body
|
||||
|
||||
if (ctx.request && ctx.request.header && ctx.request.header.authorization) {
|
||||
try {
|
||||
const {id} = await strapi.plugins[
|
||||
'users-permissions'
|
||||
].services.jwt.getToken(ctx)
|
||||
|
||||
if (id !== data.user.id) {
|
||||
return ctx.unauthorized('Opération non autorisée')
|
||||
}
|
||||
} catch (err) {
|
||||
return ctx.unauthorized('Opération non autorisée')
|
||||
}
|
||||
}
|
||||
|
||||
const user = await strapi.documents('plugin::users-permissions.user').findOne({
|
||||
documentId: body.data.user.documentId
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user