CASL and Cancan. Permissions sharing between UI and API.

Sergii Stotskyi
May 15, 2018 · 4 min read
Image for post
Image for post
CASL + Vue + Rails

Share Permissions

Whenever possible, define permissions on server side and share them with client side. This approach works very nice if you use Node.js because you can use CASL on both sides and easily transfer rules using JWT token as an example.

Integration Example

Image for post
Image for post
CASL + Vue + Vuex + REST API

REST API

There is not much to explain in server app. This is just a basic Rails application which renders JSON in response to requests. All authorization logic was done using load_and_authorize_resource controller helper function.

Vue app

CASL is shipped together with complementary package for Vue. This package adds $can method into all Vue components and that makes possible to check permissions easily in templates. For example:

Looking for more?

Read documentation and other articles about CASL:

Image for post
Image for post

DailyJS

JavaScript news and opinion.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store