@drmhse/authos-vue 0.1.3 → 0.1.4

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/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as vue from 'vue';
2
- import { App, PropType, VNode } from 'vue';
2
+ import { App, ComputedRef, PropType, VNode } from 'vue';
3
3
  import * as _drmhse_sso_sdk from '@drmhse/sso-sdk';
4
4
  import { TokenStorage, UserProfile, OrganizationResponse, SsoClient } from '@drmhse/sso-sdk';
5
5
  export { AuthErrorCodes, BrowserStorage, MemoryStorage, OrganizationResponse, SsoApiError, SsoClient, TokenStorage, UserProfile } from '@drmhse/sso-sdk';
@@ -14,10 +14,67 @@ interface AuthOSState {
14
14
  interface AuthOSContext {
15
15
  client: SsoClient;
16
16
  state: AuthOSState;
17
+ /** The plugin configuration options */
18
+ options: AuthOSPluginOptions;
17
19
  }
20
+ /**
21
+ * Configuration options for the AuthOS Vue plugin.
22
+ *
23
+ * Supports two modes:
24
+ * - **Platform-level**: Just `baseURL` for platform owners/admins (email/password only)
25
+ * - **Multi-tenant**: With `org` and `service` for tenant apps (enables OAuth)
26
+ *
27
+ * @example Platform-level access
28
+ * ```ts
29
+ * app.use(createAuthOS({
30
+ * baseURL: 'https://sso.example.com',
31
+ * }));
32
+ * ```
33
+ *
34
+ * @example Multi-tenant with OAuth
35
+ * ```ts
36
+ * app.use(createAuthOS({
37
+ * baseURL: 'https://sso.example.com',
38
+ * org: 'my-org',
39
+ * service: 'my-app',
40
+ * }));
41
+ * ```
42
+ */
18
43
  interface AuthOSPluginOptions {
19
- baseUrl: string;
44
+ /**
45
+ * Base URL of the AuthOS API service.
46
+ * @example 'https://sso.example.com'
47
+ */
48
+ baseURL: string;
49
+ /**
50
+ * Organization slug for OAuth flows.
51
+ * Only required when using OAuth login buttons.
52
+ * Omit for platform-level access.
53
+ * @example 'acme-corp'
54
+ */
55
+ org?: string;
56
+ /**
57
+ * Service slug for OAuth flows.
58
+ * Only required when using OAuth login buttons.
59
+ * Omit for platform-level access.
60
+ * @example 'main-app'
61
+ */
62
+ service?: string;
63
+ /**
64
+ * Redirect URI after OAuth authentication.
65
+ * Defaults to current window location origin + '/callback'.
66
+ * @example 'https://app.example.com/callback'
67
+ */
68
+ redirectUri?: string;
69
+ /**
70
+ * Custom storage provider (optional).
71
+ * Defaults to localStorage in browser, Memory in SSR.
72
+ */
20
73
  storage?: TokenStorage;
74
+ /**
75
+ * Automatically refresh expired tokens.
76
+ * @default true
77
+ */
21
78
  autoRefresh?: boolean;
22
79
  /**
23
80
  * Initial session token from server-side (for SSR hydration).
@@ -25,15 +82,46 @@ interface AuthOSPluginOptions {
25
82
  * Typically passed from cookies in Nuxt server components.
26
83
  */
27
84
  initialToken?: string;
85
+ /**
86
+ * URL to redirect to after successful sign-in.
87
+ * @example '/dashboard'
88
+ */
89
+ afterSignInUrl?: string;
90
+ /**
91
+ * URL to redirect to after successful sign-up.
92
+ * @example '/onboarding'
93
+ */
94
+ afterSignUpUrl?: string;
28
95
  }
29
96
  declare const AUTH_OS_INJECTION_KEY: unique symbol;
97
+ /**
98
+ * Supported OAuth providers
99
+ */
100
+ type SupportedOAuthProvider = 'github' | 'google' | 'microsoft';
30
101
 
31
102
  declare function createAuthOS(options: AuthOSPluginOptions): {
32
103
  install(app: App): void;
33
104
  };
34
105
 
106
+ /**
107
+ * Access the AuthOS client, state, and configuration.
108
+ *
109
+ * @example
110
+ * ```vue
111
+ * <script setup>
112
+ * import { useAuthOS } from '@drmhse/authos-vue';
113
+ *
114
+ * const { client, isAuthenticated, isLoading, options } = useAuthOS();
115
+ *
116
+ * async function handleLogout() {
117
+ * await client.auth.logout();
118
+ * }
119
+ * </script>
120
+ * ```
121
+ */
35
122
  declare function useAuthOS(): {
36
123
  client: SsoClient;
124
+ options: AuthOSPluginOptions;
37
125
  isLoading: vue.ComputedRef<boolean>;
38
126
  isAuthenticated: vue.ComputedRef<boolean>;
39
127
  };
@@ -46,6 +134,24 @@ declare function useUser(): {
46
134
  isLoading: vue.ComputedRef<boolean>;
47
135
  };
48
136
 
137
+ /**
138
+ * Composable to access the current organization context and switch between organizations.
139
+ *
140
+ * When switching organizations, this calls the backend to issue new JWT tokens
141
+ * with the organization context, enabling seamless organization switching without
142
+ * requiring re-authentication.
143
+ *
144
+ * @returns The current organization and a function to switch organizations
145
+ *
146
+ * @example
147
+ * ```vue
148
+ * <script setup>
149
+ * import { useOrganization } from '@drmhse/authos-vue';
150
+ *
151
+ * const { currentOrganization, switchOrganization, isSwitching } = useOrganization();
152
+ * </script>
153
+ * ```
154
+ */
49
155
  declare function useOrganization(): {
50
156
  currentOrganization: vue.Ref<null, null>;
51
157
  organizations: vue.Ref<never[], never[]>;
@@ -58,11 +164,76 @@ declare function useOrganization(): {
58
164
  isSwitching: vue.Ref<boolean, boolean>;
59
165
  };
60
166
 
167
+ /**
168
+ * Check if the current user has a specific permission.
169
+ *
170
+ * @param permission The permission to check
171
+ * @returns A computed ref that is true if the user has the permission
172
+ *
173
+ * @example
174
+ * ```vue
175
+ * <script setup>
176
+ * import { usePermission } from '@drmhse/authos-vue';
177
+ *
178
+ * const canAccessAdmin = usePermission('admin:access');
179
+ * </script>
180
+ *
181
+ * <template>
182
+ * <button v-if="canAccessAdmin">Admin Panel</button>
183
+ * </template>
184
+ * ```
185
+ */
186
+ declare function usePermission(permission: string): ComputedRef<boolean>;
187
+ /**
188
+ * Check if the current user has any of the specified permissions.
189
+ *
190
+ * @param permissions The permissions to check
191
+ * @returns A computed ref that is true if the user has any of the permissions
192
+ *
193
+ * @example
194
+ * ```vue
195
+ * <script setup>
196
+ * import { useAnyPermission } from '@drmhse/authos-vue';
197
+ *
198
+ * const canAccessReports = useAnyPermission(['reports:read', 'admin:access']);
199
+ * </script>
200
+ * ```
201
+ */
202
+ declare function useAnyPermission(permissions: string[]): ComputedRef<boolean>;
203
+ /**
204
+ * Check if the current user has all of the specified permissions.
205
+ *
206
+ * @param permissions The permissions to check
207
+ * @returns A computed ref that is true if the user has all of the permissions
208
+ *
209
+ * @example
210
+ * ```vue
211
+ * <script setup>
212
+ * import { useAllPermissions } from '@drmhse/authos-vue';
213
+ *
214
+ * const canManageBilling = useAllPermissions(['billing:read', 'billing:write']);
215
+ * </script>
216
+ * ```
217
+ */
218
+ declare function useAllPermissions(permissions: string[]): ComputedRef<boolean>;
219
+
61
220
  declare const AuthOSProvider: vue.DefineComponent<vue.ExtractPropTypes<{
62
- baseUrl: {
221
+ baseURL: {
63
222
  type: StringConstructor;
64
223
  required: true;
65
224
  };
225
+ org: {
226
+ type: StringConstructor;
227
+ default: undefined;
228
+ };
229
+ service: {
230
+ type: StringConstructor;
231
+ default: undefined;
232
+ };
233
+ redirectUri: {
234
+ type: StringConstructor;
235
+ default: undefined;
236
+ };
66
237
  storage: {
67
238
  type: PropType<TokenStorage>;
68
239
  default: undefined;
@@ -76,10 +247,22 @@ declare const AuthOSProvider: vue.DefineComponent<vue.ExtractPropTypes<{
76
247
  }> | vue.VNode<vue.RendererNode, vue.RendererElement, {
77
248
  [key: string]: any;
78
249
  }>[], {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
79
- baseUrl: {
250
+ baseURL: {
80
251
  type: StringConstructor;
81
252
  required: true;
82
253
  };
254
+ org: {
255
+ type: StringConstructor;
256
+ default: undefined;
257
+ };
258
+ service: {
259
+ type: StringConstructor;
260
+ default: undefined;
261
+ };
262
+ redirectUri: {
263
+ type: StringConstructor;
264
+ default: undefined;
265
+ };
83
266
  storage: {
84
267
  type: PropType<TokenStorage>;
85
268
  default: undefined;
@@ -89,6 +272,9 @@ declare const AuthOSProvider: vue.DefineComponent<vue.ExtractPropTypes<{
89
272
  default: undefined;
90
273
  };
91
274
  }>> & Readonly<{}>, {
275
+ org: string;
276
+ service: string;
277
+ redirectUri: string;
92
278
  storage: TokenStorage;
93
279
  client: SsoClient;
94
280
  }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
@@ -272,4 +458,184 @@ declare const Protect: vue.DefineComponent<vue.ExtractPropTypes<{
272
458
  }> | (() => VNode);
273
459
  }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
274
460
 
275
- export { AUTH_OS_INJECTION_KEY, type AuthOSContext, type AuthOSPluginOptions, AuthOSProvider, type AuthOSState, OrganizationSwitcher, type OrganizationSwitcherSlotProps, Protect, SignIn, type SignInSlotProps, SignUp, type SignUpSlotProps, UserButton, type UserButtonSlotProps, createAuthOS, useAuthOS, useOrganization, useUser };
461
+ interface OAuthButtonSlotProps {
462
+ provider: SupportedOAuthProvider;
463
+ providerName: string;
464
+ isConfigured: boolean;
465
+ disabled: boolean;
466
+ handleClick: () => void;
467
+ }
468
+ /**
469
+ * OAuth login button for a specific provider.
470
+ * Redirects the user to the OAuth provider's login page.
471
+ *
472
+ * Requires `org` and `service` to be configured in createAuthOS options.
473
+ *
474
+ * @example
475
+ * ```vue
476
+ * <script setup>
477
+ * import { OAuthButton } from '@drmhse/authos-vue';
478
+ * </script>
479
+ *
480
+ * <template>
481
+ * <OAuthButton provider="github" />
482
+ * <OAuthButton provider="google">Sign in with Google</OAuthButton>
483
+ * </template>
484
+ * ```
485
+ */
486
+ declare const OAuthButton: vue.DefineComponent<vue.ExtractPropTypes<{
487
+ provider: {
488
+ type: PropType<SupportedOAuthProvider>;
489
+ required: true;
490
+ };
491
+ disabled: {
492
+ type: BooleanConstructor;
493
+ default: boolean;
494
+ };
495
+ }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
496
+ [key: string]: any;
497
+ }> | vue.VNode<vue.RendererNode, vue.RendererElement, {
498
+ [key: string]: any;
499
+ }>[], {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, "redirect"[], "redirect", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
500
+ provider: {
501
+ type: PropType<SupportedOAuthProvider>;
502
+ required: true;
503
+ };
504
+ disabled: {
505
+ type: BooleanConstructor;
506
+ default: boolean;
507
+ };
508
+ }>> & Readonly<{
509
+ onRedirect?: ((...args: any[]) => any) | undefined;
510
+ }>, {
511
+ disabled: boolean;
512
+ }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
513
+
514
+ /**
515
+ * Renders children only when the user is authenticated.
516
+ * Use with SignedOut to create conditional UI based on auth state.
517
+ *
518
+ * @example
519
+ * ```vue
520
+ * <script setup>
521
+ * import { SignedIn, SignedOut, UserButton, SignIn } from '@drmhse/authos-vue';
522
+ * </script>
523
+ *
524
+ * <template>
525
+ * <header>
526
+ * <SignedIn>
527
+ * <UserButton />
528
+ * </SignedIn>
529
+ * <SignedOut>
530
+ * <SignIn />
531
+ * </SignedOut>
532
+ * </header>
533
+ * </template>
534
+ * ```
535
+ */
536
+ declare const SignedIn: vue.DefineComponent<{}, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
537
+ [key: string]: any;
538
+ }>[] | null | undefined, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
539
+
540
+ /**
541
+ * Renders children only when the user is NOT authenticated.
542
+ * Use with SignedIn to create conditional UI based on auth state.
543
+ *
544
+ * @example
545
+ * ```vue
546
+ * <script setup>
547
+ * import { SignedIn, SignedOut, UserButton, SignIn } from '@drmhse/authos-vue';
548
+ * </script>
549
+ *
550
+ * <template>
551
+ * <header>
552
+ * <SignedIn>
553
+ * <UserButton />
554
+ * </SignedIn>
555
+ * <SignedOut>
556
+ * <SignIn />
557
+ * </SignedOut>
558
+ * </header>
559
+ * </template>
560
+ * ```
561
+ */
562
+ declare const SignedOut: vue.DefineComponent<{}, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
563
+ [key: string]: any;
564
+ }>[] | null | undefined, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
565
+
566
+ /**
567
+ * Passwordless sign-in via magic link (email).
568
+ *
569
+ * Sends a one-time login link to the user's email address.
570
+ *
571
+ * @example
572
+ * ```vue
573
+ * <script setup>
574
+ * import { MagicLinkSignIn } from '@drmhse/authos-vue';
575
+ * </script>
576
+ *
577
+ * <template>
578
+ * <MagicLinkSignIn @success="() => alert('Check your email!')" />
579
+ * </template>
580
+ * ```
581
+ */
582
+ declare const MagicLinkSignIn: vue.DefineComponent<vue.ExtractPropTypes<{
583
+ showPasswordSignIn: {
584
+ type: BooleanConstructor;
585
+ default: boolean;
586
+ };
587
+ }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
588
+ [key: string]: any;
589
+ }> | vue.VNode<vue.RendererNode, vue.RendererElement, {
590
+ [key: string]: any;
591
+ }>[], {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, ("success" | "error")[], "success" | "error", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
592
+ showPasswordSignIn: {
593
+ type: BooleanConstructor;
594
+ default: boolean;
595
+ };
596
+ }>> & Readonly<{
597
+ onSuccess?: ((...args: any[]) => any) | undefined;
598
+ onError?: ((...args: any[]) => any) | undefined;
599
+ }>, {
600
+ showPasswordSignIn: boolean;
601
+ }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
602
+
603
+ /**
604
+ * Passkey (WebAuthn) sign-in component.
605
+ *
606
+ * Uses the Web Authentication API for passwordless authentication
607
+ * via biometrics, security keys, or platform authenticators.
608
+ *
609
+ * @example
610
+ * ```vue
611
+ * <script setup>
612
+ * import { PasskeySignIn } from '@drmhse/authos-vue';
613
+ * </script>
614
+ *
615
+ * <template>
616
+ * <PasskeySignIn @success="() => router.push('/dashboard')" />
617
+ * </template>
618
+ * ```
619
+ */
620
+ declare const PasskeySignIn: vue.DefineComponent<vue.ExtractPropTypes<{
621
+ showPasswordSignIn: {
622
+ type: BooleanConstructor;
623
+ default: boolean;
624
+ };
625
+ }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
626
+ [key: string]: any;
627
+ }> | vue.VNode<vue.RendererNode, vue.RendererElement, {
628
+ [key: string]: any;
629
+ }>[], {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, ("success" | "error")[], "success" | "error", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
630
+ showPasswordSignIn: {
631
+ type: BooleanConstructor;
632
+ default: boolean;
633
+ };
634
+ }>> & Readonly<{
635
+ onSuccess?: ((...args: any[]) => any) | undefined;
636
+ onError?: ((...args: any[]) => any) | undefined;
637
+ }>, {
638
+ showPasswordSignIn: boolean;
639
+ }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
640
+
641
+ export { AUTH_OS_INJECTION_KEY, type AuthOSContext, type AuthOSPluginOptions, AuthOSProvider, type AuthOSState, MagicLinkSignIn, OAuthButton, type OAuthButtonSlotProps, OrganizationSwitcher, type OrganizationSwitcherSlotProps, PasskeySignIn, Protect, SignIn, type SignInSlotProps, SignUp, type SignUpSlotProps, SignedIn, SignedOut, type SupportedOAuthProvider, UserButton, type UserButtonSlotProps, createAuthOS, useAllPermissions, useAnyPermission, useAuthOS, useOrganization, usePermission, useUser };