jefferyliang / koa-2-acl Goto Github PK
View Code? Open in Web Editor NEWACL middleware of koa 2
ACL middleware of koa 2
It seems using if (typeof role.length) {
to identify array, but it is true when role
is a string.
So will show error: TypeError: role.map is not a function
.
Why not use if (typeof role == 'object') {
?
https://github.com/JefferyLiang/koa-2-acl/blob/master/lib/index.js#L57
But when I update it, there will be other error.
It seems the code is not updated correctly, and some config like multipleRolePropertyName
is not in document.
Hello, i've been trying to integrate this package with Koach with no success. i added koa-2-acl on the router.js but it could not working. can you pls take a look at it
// user model
const User = new mongoose.Schema({
type: { type: String, default: 'User' },
role: { type: String, default: 'User' },
name: { type: String },
username: { type: String, required: true, unique: true },
password: { type: String, required: true }
})
import glob from 'glob'
import acl from 'koa-2-acl'
import Router from 'koa-router'
exports = module.exports = function initModules (app) {
glob(`${__dirname}/*`, { ignore: '**/index.js' }, (err, matches) => {
if (err) { throw err }
matches.forEach((mod) => {
const router = require(`${mod}/router`)
const routes = router.default
const baseUrl = router.baseUrl
const instance = new Router({ prefix: baseUrl })
routes.forEach((config) => {
const {
method = '',
route = '',
handlers = []
} = config
const lastHandler = handlers.pop()
instance[method.toLowerCase()](route, ...handlers, async function (ctx) {
await lastHandler(ctx)
})
app
.use(instance.routes())
.use(instance.allowedMethods())
.use(acl.authorize)
})
})
})
}
role does not exist on the ctx.request.decoded (jsonwebtoken) or ctx.request.session. it exist on ctx.state.user
Here is the command and its result. Module is not getting installed but throwing weird errors like this.
npm i koa-2-acl
npm WARN ********* No repository field.
npm ERR! code ENOENT
npm ERR! syscall chmod
npm ERR! path /*********/node_modules/koa-2-acl/node_modules/.bin/eslint
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, chmod '/*********/node_modules/koa-2-acl/node_modules/.bin/eslint'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /*********/.npm/_logs/2020-02-06T11_54_34_041Z-debug.log
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.