3.0.17 • Published 3 years ago
sx-licensing-manager v3.0.17
📖 Implementation
Copy the following code in the entry point of your application for example: main.ts or main.js.
import useLicesingManagerAdapter from "sx-licensing-manager";
useLicesingManagerAdapter(Vue, {
applicationId: 'your application id',
applicationServer: 'the server of the Licensing API',
})
Your entry point should look like this:
import Vue from 'vue'
import App from './App.vue'
import useLicesingManagerAdapter from "sx-licensing-manager";
Vue.config.productionTip = false
useLicesingManagerAdapter(Vue, {
applicationId: 'your application id',
applicationServer: 'the server of the Licensing API',
})
new Vue({
render: h => h(App),
}).$mount('#app')
🔥 Usage
Where validate the user who will log in:
this.templateIsReady = await this.$sxLicesingManager.setLicensingPermissions(user)
Create the variable templateIsReady and do not condition the render of the app with this
<template v-if="templateIsReady">
<nav-bar />
<div class="columns" id="mail-app">
<side-bar />
<div class="column is-10 messages hero is-fullheight">
<div class="card gray-container">
<div class="card-content">
<router-view></router-view>
</div>
</div>
</div>
</div>
</template>
In your vue template you need to put the directive licensing-permission and the function code declared in SX-Licensing-Manager as parameter
<template>
<div>
<router-link licensing-permission="'your function code'" to="/user" class="item">
<span class="icon">
<i class="fa fa-users"></i>
</span>
<span class="name">Usuarios</span>
</router-link>
</div>
</template>
In the case of wanting to validate the permissions from the code
public myFunction(): void {
if (this.$sxLicesingManager.hasLicensingPermission('your function code')) {
console.log('I am cool');
} else {
console.log('you does not have permission');
}
}
In the prototype $sxLicesingManager we have: hasLicensingPermission, setLicensingPermissions, getLicensingPermissions
Note
if you use typescript be sure to add the typing
declare module 'vue/types/vue' {
interface Vue {
$sxLicesingManager: any
}
}