@bagelink/auth 1.7.88 → 1.7.92

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.
package/dist/useAuth.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { App } from 'vue';
1
+ import { App, ObjectPlugin } from 'vue';
2
2
  import { AccountInfo, User, NewUser, UpdatePasswordForm, UpdateAccountRequest, AuthEventMap, SSOProvider, SSOInitiateRequest, SSOCallbackRequest, SSOLinkRequest, AuthState } from './types';
3
3
  import { RedirectConfig, NormalizedRedirectConfig } from './types/redirect';
4
4
  interface InitParams {
@@ -9,63 +9,26 @@ interface InitParams {
9
9
  */
10
10
  redirect?: RedirectConfig;
11
11
  }
12
+ /**
13
+ * Auth instance returned by createAuth
14
+ * Implements ObjectPlugin for Vue 3.5+ compatibility
15
+ */
16
+ export interface AuthInstance extends ObjectPlugin<[]> {
17
+ on: <K extends AuthState>(event: K, handler: AuthEventMap[K]) => void;
18
+ off: <K extends AuthState>(event: K, handler: AuthEventMap[K]) => void;
19
+ removeAllListeners: <K extends AuthState>(event?: K) => void;
20
+ use: (dependency: any, options?: {
21
+ guard?: boolean;
22
+ }) => AuthInstance;
23
+ routerGuard: () => (to: any, from: any, next: any) => Promise<void>;
24
+ install: (app: App) => void;
25
+ }
12
26
  /**
13
27
  * Get the current redirect configuration
14
28
  * Used internally by router guard
15
29
  */
16
30
  export declare function getRedirectConfig(): NormalizedRedirectConfig;
17
- export declare function createAuth(params: InitParams): {
18
- on<K extends AuthState>(event: K, handler: AuthEventMap[K]): void;
19
- off<K extends AuthState>(event: K, handler: AuthEventMap[K]): void;
20
- removeAllListeners<K extends AuthState>(event?: K): void;
21
- /**
22
- * Connect external dependencies like Vue Router
23
- * Automatically sets up router guard when router is provided
24
- * @param dependency - Vue Router instance or other plugins
25
- * @param options - Configuration options
26
- * @param options.guard - Whether to automatically set up auth guard (default: true)
27
- * @example
28
- * ```ts
29
- * // Auto setup (default)
30
- * auth.use(router)
31
- *
32
- * // Manual guard control (for custom composition)
33
- * auth.use(router, { guard: false })
34
- * router.beforeEach(async (to, from, next) => {
35
- * // Custom logic first
36
- * if (!hasOrgAccess(to)) return next('/no-access')
37
- * // Then run auth guard
38
- * return auth.routerGuard()(to, from, next)
39
- * })
40
- * ```
41
- */
42
- use(dependency: any, options?: {
43
- guard?: boolean;
44
- }): /*elided*/ any;
45
- /**
46
- * Create a Vue Router navigation guard for authentication
47
- * Protects routes requiring authentication and handles redirect logic
48
- * Note: Automatically called by auth.use(router), only use directly for custom setups
49
- * @example
50
- * ```ts
51
- * // Automatic (recommended)
52
- * auth.use(router)
53
- *
54
- * // Manual (for custom setups)
55
- * router.beforeEach(auth.routerGuard())
56
- * ```
57
- */
58
- routerGuard(): any;
59
- /**
60
- * Vue plugin install method
61
- * Makes auth available globally as $auth
62
- * @example
63
- * ```ts
64
- * app.use(auth)
65
- * ```
66
- */
67
- install(app: App): void;
68
- };
31
+ export declare function createAuth(params: InitParams): AuthInstance;
69
32
  export declare function useAuth(): {
70
33
  user: import('vue').ComputedRef<User | null>;
71
34
  accountInfo: import('vue').Ref<{
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bagelink/auth",
3
3
  "type": "module",
4
- "version": "1.7.88",
4
+ "version": "1.7.92",
5
5
  "description": "Bagelink auth package",
6
6
  "author": {
7
7
  "name": "Bagel Studio",
package/src/useAuth.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { App } from 'vue'
1
+ import type { App, ObjectPlugin } from 'vue'
2
2
  import type {
3
3
  AccountInfo,
4
4
  User,
@@ -36,6 +36,19 @@ interface InitParams {
36
36
  redirect?: RedirectConfig
37
37
  }
38
38
 
39
+ /**
40
+ * Auth instance returned by createAuth
41
+ * Implements ObjectPlugin for Vue 3.5+ compatibility
42
+ */
43
+ export interface AuthInstance extends ObjectPlugin<[]> {
44
+ on: <K extends AuthState>(event: K, handler: AuthEventMap[K]) => void
45
+ off: <K extends AuthState>(event: K, handler: AuthEventMap[K]) => void
46
+ removeAllListeners: <K extends AuthState>(event?: K) => void
47
+ use: (dependency: any, options?: { guard?: boolean }) => AuthInstance
48
+ routerGuard: () => (to: any, from: any, next: any) => Promise<void>
49
+ install: (app: App) => void
50
+ }
51
+
39
52
  /**
40
53
  * Get the current redirect configuration
41
54
  * Used internally by router guard
@@ -48,7 +61,7 @@ export function getRedirectConfig(): NormalizedRedirectConfig {
48
61
  }
49
62
 
50
63
  // Initialize auth
51
- export function createAuth(params: InitParams) {
64
+ export function createAuth(params: InitParams): AuthInstance {
52
65
  if (authApi === null) {
53
66
  authApi = new AuthApi(params.baseURL)
54
67
  }