├── .babelrc
├── .env
├── .gitignore
├── .postcssrc
├── LICENSE
├── README.md
├── package-lock.json
├── package.json
├── public
├── favicon.ico
└── index.html
└── src
├── App.vue
├── assets
└── logo.png
├── components
├── ArticleList.vue
└── Confirm.vue
├── main.js
├── plugins
└── confirm.js
├── router.js
├── services
├── http.js
└── utils.js
├── store
├── ability.js
├── articles.js
├── index.js
├── notifications.js
└── storage.js
├── validation
└── index.js
└── views
├── Article.vue
├── EditArticle.vue
├── Home.vue
└── Login.vue
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | "@vue/app"
4 | ]
5 | }
--------------------------------------------------------------------------------
/.env:
--------------------------------------------------------------------------------
1 | VUE_APP_API_URL=http://localhost:3000/api
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules
3 | /dist
4 |
5 | # local env files
6 | .env.local
7 | .env.*.local
8 |
9 | # Log files
10 | npm-debug.log*
11 | yarn-debug.log*
12 | yarn-error.log*
13 |
14 | # Editor directories and files
15 | .idea
16 | .vscode
17 | *.suo
18 | *.ntvs*
19 | *.njsproj
20 | *.sln
21 |
--------------------------------------------------------------------------------
/.postcssrc:
--------------------------------------------------------------------------------
1 | {
2 | "plugins": {
3 | "autoprefixer": {}
4 | }
5 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Sergii Stotskyi
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # CASL integration example with Vue + Vuex + REST API
2 |
3 | ## DEPRECATED
4 |
5 | The example has been moved to https://github.com/stalniy/casl-examples/tree/master/packages/vue-blog
6 |
7 | ----
8 |
9 | This example shows how to integrate [CASL](https://github.com/stalniy/casl) auhorization in more or less real [Vue](https://vuejs.org) application with Vuex and REST API. Read [CASL and Cancan](https://medium.com/dailyjs/casl-and-cancan-permissions-sharing-between-ui-and-api-5f1fa8b4bec) for details
10 |
11 | > Generate with vue-cli
12 |
13 | ## Installation
14 |
15 | ``` bash
16 | # install dependencies
17 | npm ci
18 |
19 | # serve with hot reload at localhost:8080
20 | npm run serve
21 | ```
22 |
23 | ## Description
24 |
25 | This application is a basic Blog application with possibility to login, logout and manage articles. User abilities are received from REST API and later stored in localStorage.
26 |
27 | `Ability` plugin for Vuex store can be found in [src/store/ability.js](src/store/ability.js).
28 | When user successfully login (i.e., `createSession` mutation is dispatched in store), ability is updated and when user logout (i.e., `destroySession` mutation is dispatched) ability is reset to read-only mode.
29 |
30 | `http` service is built on top of Fetch API with some hacky code (it is not important for this example).
31 | Also this example uses [vuetify](https://vuetifyjs.com/en/) as UI library
32 |
33 | ## Server side
34 |
35 | REST API is expected to be available at `http://localhost:3000/api` and support CORS headers.
36 | This example was tested and implemented together with [Rails5 + Cancan](https://github.com/stalniy/rails-cancan-api-example) but API can be implemented in whatever language you want.
37 | It's just a showcase that CASL can be seamlessly integrated with awesome [Cancan](https://github.com/CanCanCommunity/cancancan) ruby gem
38 |
39 | If you setup rails application, there are 2 users available:
40 | * admin - admin@freaksidea.com / 123456
41 | * member - member@freaksidea.com / 123456
42 |
43 | ## Alternative Server side API
44 |
45 | You can use [Express based API](https://github.com/stalniy/casl-express-example/tree/vue-api) together with this UI. Pay attention to the branch name, it should be `vue-api`.
46 | This API uses MongoDB as a database, so you will need to have one running on localhost or you can change the connection string in [src/app.js](https://github.com/stalniy/casl-express-example/blob/vue-api/src/app.js#L36)
47 |
48 | Also you will need to change API URL in `.env` file to `http://localhost:3030`.
49 |
50 | There are 3 users available:
51 | * admin@casl.io / 123456
52 | * another.writer@casl.io / 123456
53 | * writer@casl.io / 123456
54 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "casl-vue-api-example",
3 | "version": "0.1.0",
4 | "private": true,
5 | "scripts": {
6 | "serve": "vue-cli-service serve",
7 | "build": "vue-cli-service build"
8 | },
9 | "dependencies": {
10 | "@casl/ability": "^3.2.0",
11 | "@casl/vue": "^0.4.3",
12 | "vue": "^2.5.13",
13 | "vue-router": "^3.0.1",
14 | "vuetify": "^1.0.11",
15 | "vuex": "^3.0.1"
16 | },
17 | "devDependencies": {
18 | "@vue/cli-plugin-babel": "^4.0.5",
19 | "@vue/cli-service": "^4.0.5",
20 | "node-sass": "^4.13.0",
21 | "sass-loader": "^8.0.0",
22 | "vue-template-compiler": "^2.5.13"
23 | },
24 | "browserslist": [
25 | "> 1%",
26 | "last 2 versions",
27 | "not ie <= 8"
28 | ]
29 | }
30 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stalniy/casl-vue-api-example/638114bba5740e1b177c797ca5adf5efb941dbbc/public/favicon.ico
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |