UNPKG

supertokens-node

Version:
36 lines (35 loc) 1.4 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const error_1 = __importDefault(require("../../../../error")); const addRoleToUser = async ({ stInstance, tenantId, options, userContext, }) => { let userrolesRecipe = undefined; try { userrolesRecipe = stInstance.getRecipeInstanceOrThrow("userroles"); } catch (_) { return { status: "FEATURE_NOT_ENABLED_ERROR", }; } const requestBody = await options.req.getJSONBody(); const userId = requestBody.userId; const role = requestBody.role; if (role === undefined || typeof role !== "string") { throw new error_1.default({ message: "Required parameter 'role' is missing or has an invalid type", type: error_1.default.BAD_INPUT_ERROR, }); } if (userId === undefined || typeof userId !== "string") { throw new error_1.default({ message: "Required parameter 'userId' is missing or has an invalid type", type: error_1.default.BAD_INPUT_ERROR, }); } const response = await userrolesRecipe.recipeInterfaceImpl.addRoleToUser({ userId, role, tenantId, userContext }); return response; }; exports.default = addRoleToUser;