idenplane-vue 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +149 -0
  2. package/package.json +73 -0
package/README.md ADDED
@@ -0,0 +1,149 @@
1
+ # idenplane-vue
2
+
3
+ Vue 3 SDK for [Idenplane](https://github.com/idenplane/idenplane) — composables, a Vue plugin, Vue Router guard, and an `AuthProvider` component.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install idenplane-vue idenplane-sdk vue
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ### 1. Install the plugin
14
+
15
+ ```typescript
16
+ // main.ts
17
+ import { createApp } from 'vue';
18
+ import { IdenplanePlugin } from 'idenplane-vue';
19
+ import App from './App.vue';
20
+
21
+ const app = createApp(App);
22
+
23
+ app.use(IdenplanePlugin, {
24
+ url: 'http://localhost:3000',
25
+ realm: 'my-realm',
26
+ clientId: 'my-app',
27
+ redirectUri: 'http://localhost:5173/callback',
28
+ });
29
+
30
+ app.mount('#app');
31
+ ```
32
+
33
+ ### 2. Use `useAuth` in components
34
+
35
+ ```vue
36
+ <script setup lang="ts">
37
+ import { useAuth } from 'idenplane-vue';
38
+
39
+ const { isAuthenticated, user, login, logout, isLoading } = useAuth();
40
+ </script>
41
+
42
+ <template>
43
+ <div v-if="isLoading">Loading...</div>
44
+ <div v-else-if="isAuthenticated">
45
+ Hello, {{ user?.name }}
46
+ <button @click="logout">Sign out</button>
47
+ </div>
48
+ <div v-else>
49
+ <button @click="login()">Sign in</button>
50
+ </div>
51
+ </template>
52
+ ```
53
+
54
+ ### 3. Protect routes with the navigation guard
55
+
56
+ ```typescript
57
+ // router/index.ts
58
+ import { createRouter, createWebHistory } from 'vue-router';
59
+ import { createAuthGuard } from 'idenplane-vue';
60
+ import { IdenplaneClient } from 'idenplane-sdk';
61
+
62
+ const authClient = new IdenplaneClient({
63
+ url: 'http://localhost:3000',
64
+ realm: 'my-realm',
65
+ clientId: 'my-app',
66
+ redirectUri: 'http://localhost:5173/callback',
67
+ });
68
+
69
+ const router = createRouter({
70
+ history: createWebHistory(),
71
+ routes: [
72
+ { path: '/', component: Home },
73
+ {
74
+ path: '/dashboard',
75
+ component: Dashboard,
76
+ meta: { requiresAuth: true },
77
+ },
78
+ {
79
+ path: '/admin',
80
+ component: Admin,
81
+ meta: { requiresAuth: true, roles: ['admin'] },
82
+ },
83
+ ],
84
+ });
85
+
86
+ router.beforeEach(createAuthGuard({ loginRoute: '/login' }, authClient));
87
+
88
+ export default router;
89
+ ```
90
+
91
+ ### 4. AuthProvider component (scoped context)
92
+
93
+ ```vue
94
+ <!-- App.vue -->
95
+ <template>
96
+ <AuthProvider
97
+ url="http://localhost:3000"
98
+ realm="my-realm"
99
+ client-id="my-app"
100
+ redirect-uri="http://localhost:5173/callback"
101
+ >
102
+ <RouterView />
103
+ </AuthProvider>
104
+ </template>
105
+
106
+ <script setup lang="ts">
107
+ import { AuthProvider } from 'idenplane-vue';
108
+ </script>
109
+ ```
110
+
111
+ ### 5. Permissions
112
+
113
+ ```vue
114
+ <script setup lang="ts">
115
+ import { usePermissions } from 'idenplane-vue';
116
+
117
+ const { hasRole, hasPermission, roles } = usePermissions();
118
+ </script>
119
+
120
+ <template>
121
+ <AdminPanel v-if="hasRole('admin')" />
122
+ </template>
123
+ ```
124
+
125
+ ## API Reference
126
+
127
+ ### Plugin
128
+
129
+ - `IdenplanePlugin` — Vue plugin, call `app.use(IdenplanePlugin, IdenplaneConfig)`
130
+
131
+ ### Composables
132
+
133
+ - `useAuth()` — `{ isAuthenticated, user, isLoading, login, logout, getToken, client }`
134
+ - `useUser()` — `{ user, isLoading, refresh }`
135
+ - `usePermissions()` — `{ hasRole, hasPermission, roles }`
136
+
137
+ ### Navigation Guard
138
+
139
+ - `createAuthGuard(options?, client?)` — returns a `NavigationGuard`
140
+ - `options.loginRoute` — redirect path (default: `'/login'`)
141
+ - `options.roles` — global required roles
142
+
143
+ ### Components
144
+
145
+ - `<AuthProvider>` — provides auth context to a component subtree
146
+
147
+ ## License
148
+
149
+ MIT
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "idenplane-vue",
3
+ "version": "1.0.1",
4
+ "description": "Vue SDK for Idenplane Identity and Access Management Server",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
19
+ }
20
+ },
21
+ "peerDependencies": {
22
+ "idenplane-sdk": ">=1.0.0",
23
+ "vue": ">=3.0.0",
24
+ "vue-router": ">=4.0.0"
25
+ },
26
+ "peerDependenciesMeta": {
27
+ "vue-router": {
28
+ "optional": true
29
+ }
30
+ },
31
+ "scripts": {
32
+ "build": "tsup",
33
+ "dev": "tsup --watch",
34
+ "typecheck": "tsc --noEmit",
35
+ "test": "vitest run",
36
+ "test:watch": "vitest"
37
+ },
38
+ "devDependencies": {
39
+ "@vue/test-utils": "^2.4.0",
40
+ "idenplane-sdk": "file:../idenplane-js",
41
+ "jsdom": "^29.0.1",
42
+ "tsup": "^8.4.0",
43
+ "typescript": "^5.7.0",
44
+ "vitest": "^4.0.18",
45
+ "vue": "^3.5.0",
46
+ "vue-router": "^4.4.0"
47
+ },
48
+ "files": [
49
+ "dist",
50
+ "README.md"
51
+ ],
52
+ "keywords": [
53
+ "idenplane",
54
+ "oauth2",
55
+ "oidc",
56
+ "vue",
57
+ "vue3",
58
+ "authentication",
59
+ "composables"
60
+ ],
61
+ "license": "MIT",
62
+ "repository": {
63
+ "type": "git",
64
+ "url": "https://github.com/idenplane/idenplane.git",
65
+ "directory": "packages/idenplane-vue"
66
+ },
67
+ "publishConfig": {
68
+ "access": "public"
69
+ },
70
+ "overrides": {
71
+ "esbuild": ">=0.28.1"
72
+ }
73
+ }