@c8o/nimbus-core
Advanced tools
Comparing version 0.0.2 to 0.0.3
const Roles = require('../Models/Roles') | ||
const UserRoles = require('../Models/UsersRoles') | ||
const JwtHandler = require('./JwtHandler') | ||
@@ -18,11 +17,11 @@ | ||
try { | ||
const tokenObject = await JwtHandler.validate(token) | ||
const requiredRoleId = await this.getRoleIdFromRoleName(requiredRoleName) | ||
const userRolesObject = await this.getAllUserRoles(tokenObject.user.id) | ||
// const tokenObject = await JwtHandler.validate(token) | ||
// const requiredRoleId = await this.getRoleIdFromRoleName(requiredRoleName) | ||
// const userRolesObject = await this.getAllUserRoles(tokenObject.user.id) | ||
for (let i in userRolesObject) { | ||
if (userRolesObject[i].role_id === requiredRoleId._id) { | ||
return true | ||
} | ||
} | ||
// for (let i in userRolesObject) { | ||
// if (userRolesObject[i].role_id === requiredRoleId._id) { | ||
// return true | ||
// } | ||
// } | ||
} catch (error) { | ||
@@ -44,9 +43,9 @@ return error.type | ||
*/ | ||
static async getAllUserRoles(id) { | ||
try { | ||
return await UserRoles.find({ user_id: id }) | ||
} catch (error) { | ||
throw new Error(error) | ||
} | ||
} | ||
// static async getAllUserRoles(id) { | ||
// try { | ||
// return await UserRoles.find({ user_id: id }) | ||
// } catch (error) { | ||
// throw new Error(error) | ||
// } | ||
// } | ||
@@ -62,11 +61,11 @@ /** | ||
*/ | ||
static async getRoleIdFromRoleName(roleName) { | ||
try { | ||
return await Roles.findOne({ name: roleName }) | ||
} catch (error) { | ||
throw new Error(error) | ||
} | ||
} | ||
// static async getRoleIdFromRoleName(roleName) { | ||
// try { | ||
// return await Roles.findOne({ name: roleName }) | ||
// } catch (error) { | ||
// throw new Error(error) | ||
// } | ||
// } | ||
}; | ||
module.exports = AccessHandler |
{ | ||
"name": "@c8o/nimbus-core", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Nimbus core package", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12583
503