mirror of
https://github.com/strapi/strapi.git
synced 2025-12-24 13:43:41 +00:00
Check if token user still exist
This commit is contained in:
parent
c7ef225238
commit
2715f2693f
@ -6,7 +6,14 @@ module.exports = async (ctx, next) => {
|
||||
|
||||
if (ctx.request && ctx.request.header && ctx.request.header.authorization) {
|
||||
try {
|
||||
ctx.state.user = await strapi.plugins['users-permissions'].services.jwt.getToken(ctx);
|
||||
const tokenUser = await strapi.plugins['users-permissions'].services.jwt.getToken(ctx);
|
||||
|
||||
ctx.state.user = await strapi.plugins['users-permissions'].services.user.fetch(_.pick(tokenUser, ['_id', 'id']));
|
||||
|
||||
if (!ctx.state.user) {
|
||||
ctx.unauthorized('This user doesn\'t exit.');
|
||||
}
|
||||
|
||||
role = ctx.state.user.role;
|
||||
|
||||
if (role.toString() === '0') {
|
||||
|
||||
@ -19,6 +19,8 @@ module.exports = {
|
||||
if (!params[this.primaryKey] && params.id) {
|
||||
params[this.primaryKey] = params.id;
|
||||
delete params.id;
|
||||
} else if (params.id) {
|
||||
delete params.id;
|
||||
}
|
||||
|
||||
return this
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user