Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@orbiting/backend-modules-auth

Package Overview
Dependencies
Maintainers
6
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@orbiting/backend-modules-auth - npm Package Compare versions

Comparing version 0.6.1 to 0.7.0

19

CHANGELOG.md

@@ -1,6 +0,21 @@

<a name="0.6.1"></a>
## 0.6.1 (2017-11-30)
<a name="0.7.0"></a>
# 0.7.0 (2017-12-04)
<a name="0.7.0"></a>
# 0.7.0 (2017-12-04)
### Bug Fixes
* **backend-modules-auth:** simplify code ([786b1cb](https://github.com/orbiting/backend-modules/commit/786b1cb))
### Features
* **backend-modules-auth:** extend lib/Roles by userIsInRoles and ensureUserIsInRoles ([256e65d](https://github.com/orbiting/backend-modules/commit/256e65d))
<a name="0.6.1"></a>

@@ -7,0 +22,0 @@ ## 0.6.1 (2017-11-30)

@@ -6,3 +6,2 @@ const t = require('./t')

]
exports.roles = roles

@@ -12,3 +11,2 @@ const userHasRole = (user, role) => {

}
exports.userHasRole = userHasRole

@@ -22,7 +20,34 @@ const ensureUserHasRole = (user, role) => {

console.info('unauthorized', { stack: new Error().stack })
throw new Error(t('api/unauthorized', {role}))
throw new Error(t.pluralize('api/unauthorized', {
count: 1,
role: `«${role}»`
}))
}
}
exports.ensureUserHasRole = ensureUserHasRole
const userIsInRoles = (user, roles = []) => {
const matches = roles.filter( role =>
userHasRole(user, role)
)
return matches.length > 0
}
const ensureUserIsInRoles = (user, roles) => {
if (!user) {
console.info('signIn', { stack: new Error().stack })
throw new Error(t('api/signIn'))
}
if(!userIsInRoles(user, roles)) {
console.info('unauthorized', { stack: new Error().stack })
throw new Error(t.pluralize('api/unauthorized', {
count: roles.length,
role: roles
.map( role => `«${role}»`)
.join(', ')
}))
}
}
const addUserToRole = async (userId, role, pgdb) => {

@@ -43,3 +68,2 @@ await pgdb.query(`

}
exports.addUserToRole = addUserToRole

@@ -60,2 +84,11 @@ const removeUserFromRoll = async (userId, role, pgdb) => {

}
exports.removeUserFromRoll = removeUserFromRoll
module.exports = {
roles,
userHasRole,
ensureUserHasRole,
userIsInRoles,
ensureUserIsInRoles,
addUserToRole,
removeUserFromRoll
}
{
"updated": "2017-11-18T18:45:28.151Z",
"updated": "2017-12-04T14:03:33.359Z",
"title": "live",

@@ -14,2 +14,10 @@ "data": [

{
"key": "api/unauthorized/1",
"value": "Nicht genehmigt. Sie müssen die Rolle {role} besitzen um die gwünschte Aktion auszuführen."
},
{
"key": "api/unauthorized/other",
"value": "Nicht genehmigt. Sie müssen mindestens eine der folgenden Rollen {role} besitzen um die gwünschte Aktion auszuführen."
},
{
"key": "api/email/invalid",

@@ -16,0 +24,0 @@ "value": "E-Mail ungültig"

5

package.json
{
"name": "@orbiting/backend-modules-auth",
"version": "0.6.1",
"version": "0.7.0",
"description": "auth migrations, seeds, middleware, graphql schema and resolvers",
"main": "index.js",
"scripts": {
"link": "yarn link"
"link": "yarn link",
"translations": "gsheets --key=1mgLz3k2rQ_qcB2ZpmJRZbGLAX5vGcr0P9I2jbWaIgog --title=live --pretty --out lib/translations.json"
},

@@ -9,0 +10,0 @@ "repository": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc