Skip to main content

Vue SDK

Casdoor Vue SDK is designed for Vue2 and Vue3 which is very conveniently to use.

The Vue SDK is based on casdoor-js-sdk,you can also use the casdoor-js-sdk directly which will be more customizable.

This plugin is still in development, if you have any questions and suggestions, please contact us at issue

We will show you the steps below.

if you still don’t know how to use it after reading README.md, you can go to the a example: casdoor-python-vue-sdk-example for more details.

The example' front-end is built with casdoor-vue-sdk,and the back-end is built with casdoor-python-sdk,you can see the source code in the example.

Installation

# NPM
npm i casdoor-vue-sdk

# Yarn
yarn add casdoor-vue-sdk

Init SDK

Initialization requires 5 parameters, which are all string type:

Name (in order)MustDescription
serverUrlYesyour Casdoor server URL
clientIdYesthe Client ID of your Casdoor application
appNameYesthe name of your Casdoor application
organizationNameYesthe name of the Casdoor organization connected with your Casdoor application
redirectPathNothe path of the redirect URL for your Casdoor application, will be /callback if not provided

install:

For Vue3:

// in main.js
import Casdoor from 'casdoor-vue-sdk'
const config = {
serverUrl: "http://localhost:8000",
clientId: "4262bea2b293539fe45e",
organizationName: "casbin",
appName: "app-casnode",
redirectPath: "/callback",
};
const app = createApp(App)
app.use(Casdoor, config)

For Vue2:

// in main.js
import Casdoor from 'casdoor-vue-sdk'
import VueCompositionAPI from '@vue/composition-api'
const config = {
serverUrl: "http://localhost:8000",
clientId: "4262bea2b293539fe45e",
organizationName: "casbin",
appName: "app-casnode",
redirectPath: "/callback",
};
Vue.use(VueCompositionAPI)
Vue.use(Casdoor,config)
new Vue({
render: h => h(App),
}).$mount('#app')

example:

// in app.vue
<script>
export default {
name: 'App',
methods: {
login() {
window.location.href = this.getSigninUrl();
},
signup() {
window.location.href = this.getSignupUrl();
}
}
}
</script>

Auto Fix

If the postinstall hook doesn't get triggered or you have updated the Vue version, try to run the following command to resolve the redirecting.

npx vue-demi-fix

More info about Vue version switch at: vue-demi docs