fastify-casbin
Advanced tools
Comparing version 2.0.0 to 3.0.0
{ | ||
"name": "fastify-casbin", | ||
"version": "2.0.0", | ||
"version": "3.0.0", | ||
"description": "Plugin for fastify to add generic support for Casbin", | ||
@@ -42,14 +42,14 @@ "main": "plugin.js", | ||
"devDependencies": { | ||
"@types/node": "^14.14.6", | ||
"@types/node": "^17.0.0", | ||
"casbin": "^5.1.6", | ||
"fastify": "^3.7.0", | ||
"fastify": "^4.0.2", | ||
"pre-commit": "^1.2.2", | ||
"proxyquire": "^2.1.3", | ||
"sinon": "^9.2.1", | ||
"sinon": "^14.0.0", | ||
"snazzy": "^9.0.0", | ||
"standard": "^16.0.1", | ||
"tap": "^14.10.8", | ||
"tsd": "^0.13.1", | ||
"standard": "^17.0.0", | ||
"tap": "^16.0.0", | ||
"tsd": "^0.21.0", | ||
"typescript": "^4.0.5" | ||
} | ||
} |
@@ -58,24 +58,26 @@ # fastify-casbin | ||
const pgOptions = { | ||
connectionString: 'postgres://localhost' | ||
connectionString: 'postgres://localhost', | ||
migrate: true | ||
} | ||
fastify.register(require('fastify-casbin'), { | ||
model: 'basic_model.conf', // the model configuration | ||
adapter: await newAdapter(pgOptions), // the adapter | ||
watcher: await newWatcher(pgOptions) // the watcher | ||
}) | ||
async () => { | ||
fastify.register(require('fastify-casbin'), { | ||
model: 'basic_model.conf', // the model configuration | ||
adapter: await newAdapter(pgOptions), // the adapter | ||
watcher: await newWatcher(pgOptions) // the watcher | ||
}) | ||
// add some policies at application startup | ||
fastify.addHook('onReady', async function () { | ||
await fastify.casbin.addPolicy('alice', 'data1', 'read') | ||
}) | ||
// add some policies at application startup | ||
fastify.addHook('onReady', async function () { | ||
await fastify.casbin.addPolicy('alice', 'data1', 'read') | ||
}) | ||
fastify.get('/protected', async () => { | ||
if (!(await fastify.casbin.enforce('alice', 'data1', 'read'))) { | ||
throw new Error('Forbidden') | ||
} | ||
fastify.get('/protected', async () => { | ||
if (!(await fastify.casbin.enforce('alice', 'data1', 'read'))) { | ||
throw new Error('Forbidden') | ||
} | ||
return `You're in!` | ||
}) | ||
return `You're in!` | ||
}) | ||
} | ||
``` | ||
@@ -89,2 +91,3 @@ | ||
import { Model, FileAdapter } from 'casbin' | ||
import fastifyCasbin from 'fastify-casbin' | ||
@@ -100,3 +103,3 @@ const modelPath = join(__dirname, 'auth', 'basic_model.conf') | ||
fastify.register(plugin, { | ||
app.register(fastifyCasbin, { | ||
model: preloadedModel, | ||
@@ -106,4 +109,4 @@ adapter: preloadedAdapter | ||
fastify.get('/protected', async () => { | ||
if (!(await fastify.casbin.enforce('alice', 'data1', 'read'))) { | ||
app.get('/protected', async () => { | ||
if (!(await app.casbin.enforce('alice', 'data1', 'read'))) { | ||
throw new Error('Forbidden') | ||
@@ -110,0 +113,0 @@ } |
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
12951
118