@kocdigital/p360-user-vue-plugin
v0.0.4
Published
Koç Digital Platform360 User Vue Plugin
Readme
Platform360 User Vue Plugin
Overview
This Vue plugin facilitates streamlined access to user data via $jwtUser and $user global variables, fetches user data once and clears the user cache upon logout.
Installation
npm install @kocdigital/p360-user-vue-pluginyarn add @kocdigital/p360-user-vue-pluginor
yarn add git+https://github.com/kocdigital/p360-user-vue-plugin.gitnpm install git+https://github.com/kocdigital/p360-user-vue-plugin.gitUsage
After installation, you can import the plugin in your Vue application as follows:
import Vue from 'vue';
import user from '@kocdigital/p360-user-vue-plugin';
Vue.use(user);Access user models to customize user or jwt user data:
import Vue from 'vue';
import user from '@kocdigital/p360-user-vue-plugin';
import {User as DefaultUser} from '@kocdigital/p360-user-vue-plugin/models';
export class MyCustomUser extends DefaultUser {
// Your customizations here
}
Vue.use(user, {
CustomUser: MyCustomUser
});import Vue from 'vue';
import user from '@kocdigital/p360-user-vue-plugin';
import {JwtUser as DefaultJwtUser} from '@kocdigital/p360-user-vue-plugin/models';
export class MyCustomJwtUser extends DefaultJwtUser {
// Your customizations here
}
Vue.use(user, {
CustomJwtUser: MyCustomJwtUser
});Customize the user fetching logic by providing your own fetchUserById function:
import Vue from 'vue';
import user from '@kocdigital/p360-user-vue-plugin';
import type {IUser} from '@kocdigital/p360-user-vue-plugin/models';
Vue.use(user, {
fetchUserById: async (userId): Promise<IUser> => {
// Your custom fetch logic here
const response = await fetch(`/api/users/${userId}`);
const data: IUser = await response.json();
return data; // Must return `IUser`, otherwise throw type error
}
});Customize user cache target by providing storage options:
import Vue from 'vue';
import user from '@kocdigital/p360-user-vue-plugin';
Vue.use(user, {
storage: sessionStorage, // default is `localStorage`
storageKey: 'my-custom-user-cache' // default is "x-user"
});Contributing
If you would like to contribute to this project, please fork the repository and submit a pull request with your changes.
Prerequisites
- Install Node.js 18.x
- Install npm (included with Node.js).
Setup
Clone the repository:
git clone https://github.com/kocdigital/p360-user-vue-plugin.git cd p360-user-vue-pluginInstall the dependencies:
npm install
Building the Plugin
To build the plugin, you can use the following commands:
One-time build:
npm run buildContinuous build:
npm run dev
The npm run build command will create a production-ready build of the plugin, while npm run dev will run the build in watch mode, rebuilding automatically on changes.
Linking with npm
To link this vue plugin with your main application using npm, follow these steps:
In the root directory of the plugin, run:
npm linkNavigate to your main application directory:
cd path/to/your/main/applicationLink the plugin to your main application:
npm link "@kocdigital/p360-user-vue-plugin"Now you can develop features or fix bugs in the plugin and see the changes reflected in your main application without needing to publish the plugin to npm.
