From 2b05cb9655a3d483cf80efcb145cca81412ee3dd Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Thu, 27 Oct 2022 14:46:18 +0200 Subject: [PATCH] Added back route to be able to get user roles --- back/methods/account/getRoles.js | 31 +++++++++++++++++++++++++++++++ back/models/account.js | 1 + 2 files changed, 32 insertions(+) create mode 100644 back/methods/account/getRoles.js diff --git a/back/methods/account/getRoles.js b/back/methods/account/getRoles.js new file mode 100644 index 000000000..2a4e50ef2 --- /dev/null +++ b/back/methods/account/getRoles.js @@ -0,0 +1,31 @@ +module.exports = Self => { + Self.remoteMethodCtx('getUserRoles', { + description: 'Gets the user roles', + accepts: + { + arg: 'ctx', + type: 'Object', + http: {source: 'context'} + }, + returns: { + type: 'object', + root: true + }, + http: { + path: `/getUserRoles`, + verb: 'POST' + } + }); + + Self.getUserRoles = async ctx => { + // Get the user from the accesstoken + const userId = ctx.req.accessToken.userId; + + // Get the user roles + const roles = await Self.getRoles(userId, { + ctx: ctx + }); + + return roles; + }; +}; diff --git a/back/models/account.js b/back/models/account.js index f74052b5c..bb46cc2df 100644 --- a/back/models/account.js +++ b/back/models/account.js @@ -8,6 +8,7 @@ module.exports = Self => { require('../methods/account/set-password')(Self); require('../methods/account/validate-token')(Self); require('../methods/account/privileges')(Self); + require('../methods/account/getRoles')(Self); // Validations