Skip to content

Commit 0260a94

Browse files
committed
feat: Add options.storageOptions.plugins config to allow installing pinia plugins directly.
1 parent ab48fbd commit 0260a94

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

packages/vue-auth/index.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,30 @@ import { setAuthConfig } from './src/utils/config'
77
import { useAuthStore } from './src/stores/vue-auth'
88

99
// Define the plugin with the correct signature
10-
export const authPlugin = <U = unknown> (options: AuthOptions<U>) => {
10+
export const authPlugin = <U = unknown>(options: AuthOptions<U>) => {
1111
const { router, loginRouteName, defaultAuthRouteName } = options
1212

1313
const vueAuth: Plugin<[]> = {
1414
install: (app: App) => {
1515
// Store global authentication options
1616
setAuthConfig<U>(options)
1717

18-
// TODO: Document the skipInit option
18+
// TODO: Document the options.storageOptions.skipInit option
1919
// Check if Pinia is already installed
2020
const isPiniaInstalled = !!getActivePinia() || options.storageOptions?.skipInit
2121

22+
// Install Pinia if not already installed
2223
if (!isPiniaInstalled) {
2324
const pinia = createPinia()
24-
// Install Pinia if not already installed
25+
26+
// TODO: Document the plugins option
27+
// Install pinia options.storageOptions.plugins if any is provided
28+
if (options.storageOptions?.plugins) {
29+
for (let i = 0; i < options.storageOptions.plugins.length; i++) {
30+
const plugin = options.storageOptions.plugins[i]
31+
pinia.use(plugin)
32+
}
33+
}
2534
app.use(pinia)
2635
}
2736

packages/vue-auth/src/types.ts

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import 'pinia'
33
import { AxiosHeaders, RawAxiosRequestHeaders } from 'axios'
44
import { NavigationGuardNext, RouteLocationNormalized, Router } from 'vue-router'
55

6+
import { PiniaPlugin } from 'pinia'
7+
68
export interface AuthUser {
79
id: number
810
email: string
@@ -123,6 +125,10 @@ export interface StorageOptions {
123125
* @default undefined
124126
*/
125127
skipInit?: boolean
128+
/**
129+
* Load optional pinia plugins
130+
*/
131+
plugins?: PiniaPlugin[]
126132
[key: string]: any // eslint-disable-line @typescript-eslint/no-explicit-any
127133
}
128134

0 commit comments

Comments
 (0)