Commit 0260a94 1 parent ab48fbd commit 0260a94 Copy full SHA for 0260a94
File tree 2 files changed +18
-3
lines changed
2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -7,21 +7,30 @@ import { setAuthConfig } from './src/utils/config'
7
7
import { useAuthStore } from './src/stores/vue-auth'
8
8
9
9
// 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 > ) => {
11
11
const { router, loginRouteName, defaultAuthRouteName } = options
12
12
13
13
const vueAuth : Plugin < [ ] > = {
14
14
install : ( app : App ) => {
15
15
// Store global authentication options
16
16
setAuthConfig < U > ( options )
17
17
18
- // TODO: Document the skipInit option
18
+ // TODO: Document the options.storageOptions. skipInit option
19
19
// Check if Pinia is already installed
20
20
const isPiniaInstalled = ! ! getActivePinia ( ) || options . storageOptions ?. skipInit
21
21
22
+ // Install Pinia if not already installed
22
23
if ( ! isPiniaInstalled ) {
23
24
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
+ }
25
34
app . use ( pinia )
26
35
}
27
36
Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ import 'pinia'
3
3
import { AxiosHeaders , RawAxiosRequestHeaders } from 'axios'
4
4
import { NavigationGuardNext , RouteLocationNormalized , Router } from 'vue-router'
5
5
6
+ import { PiniaPlugin } from 'pinia'
7
+
6
8
export interface AuthUser {
7
9
id : number
8
10
email : string
@@ -123,6 +125,10 @@ export interface StorageOptions {
123
125
* @default undefined
124
126
*/
125
127
skipInit ?: boolean
128
+ /**
129
+ * Load optional pinia plugins
130
+ */
131
+ plugins ?: PiniaPlugin [ ]
126
132
[ key : string ] : any // eslint-disable-line @typescript-eslint/no-explicit-any
127
133
}
128
134
You can’t perform that action at this time.
0 commit comments