62 | Post content. 63 |
64 | 65 | ``` 66 | 67 | `useGlobalProperties` will mount `$can` and `$authorizer` on every component. Sometimes, you may want to use some other 68 | function as `$can`. In this condition, you can 69 | use [provide/inject API](https://v3.vuejs.org/guide/component-provide-inject.html) in Vue 3 to get the `$authorizer`. 70 | 71 | ```typescript 72 | createApp() 73 | .use(CasbinPlugin, authorizer) 74 | .mount('#app'); 75 | ``` 76 | 77 | And inject it with `AUTHORIZER_KEY` 78 | 79 | ```vue 80 | 81 | 82 |83 | Post content. 84 |
85 | 86 | 87 | 96 | ``` 97 | 98 | You can also use `useAuthorizer` function. 99 | 100 | ```vue 101 | 102 | 103 |104 | Post content. 105 |
106 | 107 | 108 | 120 | ``` 121 | 122 | ## License 123 | 124 | This project is licensed under the [Apache 2.0 license](LICENSE). 125 | 126 | ## Contact 127 | 128 | If you have any issues or feature requests, please contact us. PR is welcomed. 129 | 130 | - https://github.com/casbin-js/vue-authz/issues 131 | - hsluoyz@gmail.com 132 | - Tencent QQ group: [546057381](//shang.qq.com/wpa/qunwpa?idkey=8ac8b91fc97ace3d383d0035f7aa06f7d670fd8e8d4837347354a31c18fac885) 133 | -------------------------------------------------------------------------------- /jestconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "transform": { 3 | "^.+\\.(t|j)sx?$": "ts-jest" 4 | }, 5 | "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", 6 | "moduleFileExtensions": [ 7 | "ts", 8 | "tsx", 9 | "js", 10 | "jsx", 11 | "json", 12 | "node" 13 | ], 14 | "coveragePathIgnorePatterns": [ 15 | "/node_modules/" 16 | ] 17 | } -------------------------------------------------------------------------------- /lib/index.d.ts: -------------------------------------------------------------------------------- 1 | export { install } from './install'; 2 | export * from './useAuthorizer'; 3 | import { install } from './install'; 4 | export default install; 5 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { 3 | if (k2 === undefined) k2 = k; 4 | Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); 5 | }) : (function(o, m, k, k2) { 6 | if (k2 === undefined) k2 = k; 7 | o[k2] = m[k]; 8 | })); 9 | var __exportStar = (this && this.__exportStar) || function(m, exports) { 10 | for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); 11 | }; 12 | Object.defineProperty(exports, "__esModule", { value: true }); 13 | var install_1 = require("./install"); 14 | Object.defineProperty(exports, "install", { enumerable: true, get: function () { return install_1.install; } }); 15 | __exportStar(require("./useAuthorizer"), exports); 16 | var install_2 = require("./install"); 17 | exports.default = install_2.install; 18 | -------------------------------------------------------------------------------- /lib/install.d.ts: -------------------------------------------------------------------------------- 1 | import { App } from 'vue'; 2 | import { Authorizer } from 'casbin.js'; 3 | export interface CasbinPluginOptions { 4 | useGlobalProperties?: boolean; 5 | customProperties?: ArrayThis is a webpack development test page.
9 | 10 | 13 | 14 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Visit https://aka.ms/tsconfig.json to read more about this file */ 4 | 5 | /* Basic Options */ 6 | // "incremental": true, /* Enable incremental compilation */ 7 | "target": "es5", 8 | /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ 9 | "module": "commonjs", 10 | /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ 11 | "lib": [ 12 | "es6", 13 | "DOM" 14 | ], 15 | /* Specify library files to be included in the compilation. */ 16 | // "allowJs": true, /* Allow javascript files to be compiled. */ 17 | // "checkJs": true, /* Report errors in .js files. */ 18 | // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ 19 | "declaration": true, 20 | /* Generates corresponding '.d.ts' file. */ 21 | // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ 22 | // "sourceMap": true, /* Generates corresponding '.map' file. */ 23 | // "outFile": "./", /* Concatenate and emit output to single file. */ 24 | "outDir": "./lib", 25 | /* Redirect output structure to the directory. */ 26 | // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ 27 | // "composite": true, /* Enable project compilation */ 28 | // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ 29 | // "removeComments": true, /* Do not emit comments to output. */ 30 | // "noEmit": true, /* Do not emit outputs. */ 31 | // "importHelpers": true, /* Import emit helpers from 'tslib'. */ 32 | // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ 33 | // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ 34 | 35 | /* Strict Type-Checking Options */ 36 | "strict": false, 37 | /* Enable all strict type-checking options. */ 38 | // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ 39 | // "strictNullChecks": true, /* Enable strict null checks. */ 40 | // "strictFunctionTypes": true, /* Enable strict checking of function types. */ 41 | // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ 42 | // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ 43 | // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ 44 | // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ 45 | 46 | /* Additional Checks */ 47 | // "noUnusedLocals": true, /* Report errors on unused locals. */ 48 | // "noUnusedParameters": true, /* Report errors on unused parameters. */ 49 | // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ 50 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ 51 | 52 | /* Module Resolution Options */ 53 | // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ 54 | // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ 55 | // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ 56 | // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ 57 | // "typeRoots": [], /* List of folders to include type definitions from. */ 58 | // "types": [], /* Type declaration files to be included in compilation. */ 59 | // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ 60 | "esModuleInterop": true, 61 | /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ 62 | // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ 63 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ 64 | 65 | /* Source Map Options */ 66 | // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ 67 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 68 | // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ 69 | // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ 70 | 71 | /* Experimental Options */ 72 | // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ 73 | // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ 74 | 75 | /* Advanced Options */ 76 | "skipLibCheck": true, 77 | /* Skip type checking of declaration files. */ 78 | "forceConsistentCasingInFileNames": true 79 | /* Disallow inconsistently-cased references to the same file. */ 80 | }, 81 | "include": [ 82 | "./src" 83 | ], 84 | "exclude": [ 85 | "node_modules", 86 | "**/__test__/*" 87 | ] 88 | } -------------------------------------------------------------------------------- /webpack.base.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const { CleanWebpackPlugin } = require('clean-webpack-plugin'); 3 | const HtmlWebpackPlugin = require('html-webpack-plugin'); 4 | 5 | 6 | module.exports = { 7 | entry: './src/index.ts', 8 | module: { 9 | rules: [ 10 | { 11 | test: /\.tsx?$/, 12 | use: 'ts-loader', 13 | exclude: /node_modules/, 14 | }, 15 | { 16 | test: /\.jsx?$/, 17 | use: { 18 | loader: 'babel-loader', 19 | options: { 20 | presets: ['@babel/preset-env'], 21 | plugins: ['@babel/plugin-proposal-optional-chaining'] 22 | }, 23 | }, 24 | } 25 | ], 26 | }, 27 | resolve: { 28 | extensions: [ '.tsx', '.ts', '.js' ], 29 | }, 30 | 31 | output: { 32 | library: 'vue-casbin', 33 | libraryTarget: 'module', 34 | filename: 'vue-casbin.js', 35 | path: path.resolve(__dirname, 'dist'), 36 | }, 37 | plugins: [ 38 | new CleanWebpackPlugin() 39 | ] 40 | }; -------------------------------------------------------------------------------- /webpack.dev.js: -------------------------------------------------------------------------------- 1 | const { merge } = require('webpack-merge'); 2 | const HtmlWebpackPlugin = require('html-webpack-plugin'); 3 | const base = require('./webpack.base'); 4 | 5 | module.exports = merge(base, { 6 | mode: 'development', 7 | devtool: 'inline-source-map', 8 | devServer: { 9 | contentBase: './dist', 10 | port: 9001 11 | }, 12 | plugins: [ 13 | new HtmlWebpackPlugin({ 14 | 'title': 'Development', 15 | 'filename': 'index.html', 16 | 'template': './src/webpack-dev-server-template.html', 17 | 'inject': false 18 | }) 19 | ] 20 | 21 | }) -------------------------------------------------------------------------------- /webpack.prod.js: -------------------------------------------------------------------------------- 1 | const { merge } = require('webpack-merge'); 2 | const base = require('./webpack.base'); 3 | module.exports = merge(base, { 4 | mode: 'production' 5 | }) --------------------------------------------------------------------------------