@drmhse/authos-react 0.1.3 → 0.1.5
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/README.md +278 -167
- package/dist/index.d.mts +266 -16
- package/dist/index.d.ts +266 -16
- package/dist/index.js +288 -48
- package/dist/index.mjs +285 -50
- package/dist/nextjs.d.mts +30 -1
- package/dist/nextjs.d.ts +30 -1
- package/dist/nextjs.js +11 -0
- package/dist/nextjs.mjs +10 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -3,14 +3,56 @@ import * as _drmhse_sso_sdk from '@drmhse/sso-sdk';
|
|
|
3
3
|
import { SsoClientOptions, SsoClient, UserProfile, Organization } from '@drmhse/sso-sdk';
|
|
4
4
|
export { AuthErrorCodes, Organization, SsoApiError, SsoClient, SsoClientOptions, UserProfile } from '@drmhse/sso-sdk';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Extended configuration options for the AuthOS React provider.
|
|
8
|
+
*
|
|
9
|
+
* Supports two modes:
|
|
10
|
+
* - **Platform-level**: Just `baseURL` for platform owners/admins (email/password only)
|
|
11
|
+
* - **Multi-tenant**: With `org` and `service` for tenant apps (enables OAuth)
|
|
12
|
+
*/
|
|
13
|
+
interface AuthOSConfig extends SsoClientOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Organization slug for OAuth flows.
|
|
16
|
+
* Only required when using OAuth login buttons.
|
|
17
|
+
* Omit for platform-level access.
|
|
18
|
+
* @example 'acme-corp'
|
|
19
|
+
*/
|
|
20
|
+
org?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Service slug for OAuth flows.
|
|
23
|
+
* Only required when using OAuth login buttons.
|
|
24
|
+
* Omit for platform-level access.
|
|
25
|
+
* @example 'main-app'
|
|
26
|
+
*/
|
|
27
|
+
service?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Redirect URI after OAuth authentication.
|
|
30
|
+
* Defaults to current window location origin + '/callback'.
|
|
31
|
+
* @example 'https://app.example.com/callback'
|
|
32
|
+
*/
|
|
33
|
+
redirectUri?: string;
|
|
34
|
+
/**
|
|
35
|
+
* URL to redirect to after successful sign-in.
|
|
36
|
+
* If not set, user stays on current page.
|
|
37
|
+
* @example '/dashboard'
|
|
38
|
+
*/
|
|
39
|
+
afterSignInUrl?: string;
|
|
40
|
+
/**
|
|
41
|
+
* URL to redirect to after successful sign-up.
|
|
42
|
+
* If not set, user stays on current page.
|
|
43
|
+
* @example '/onboarding'
|
|
44
|
+
*/
|
|
45
|
+
afterSignUpUrl?: string;
|
|
46
|
+
}
|
|
6
47
|
/**
|
|
7
48
|
* Configuration options for the AuthOS React provider
|
|
8
49
|
*/
|
|
9
50
|
interface AuthOSProviderProps {
|
|
10
51
|
/**
|
|
11
|
-
* SDK configuration options
|
|
52
|
+
* SDK and OAuth configuration options.
|
|
53
|
+
* At minimum, requires `baseURL`. For OAuth flows, also set `org` and `service`.
|
|
12
54
|
*/
|
|
13
|
-
config:
|
|
55
|
+
config: AuthOSConfig;
|
|
14
56
|
/**
|
|
15
57
|
* React children
|
|
16
58
|
*/
|
|
@@ -32,6 +74,8 @@ interface AuthOSProviderProps {
|
|
|
32
74
|
interface AuthOSContextState {
|
|
33
75
|
/** The underlying SDK client instance */
|
|
34
76
|
client: SsoClient;
|
|
77
|
+
/** The provider configuration */
|
|
78
|
+
config: AuthOSConfig;
|
|
35
79
|
/** Current authenticated user, or null if not authenticated */
|
|
36
80
|
user: UserProfile | null;
|
|
37
81
|
/** Whether the user is authenticated */
|
|
@@ -61,6 +105,19 @@ interface SignInProps {
|
|
|
61
105
|
showSignUp?: boolean;
|
|
62
106
|
/** Custom class name for the form container */
|
|
63
107
|
className?: string;
|
|
108
|
+
/**
|
|
109
|
+
* OAuth providers to display as buttons.
|
|
110
|
+
* Set to false to hide all OAuth buttons, or provide an array of providers.
|
|
111
|
+
* @default false (no OAuth buttons shown by default)
|
|
112
|
+
* @example ['github', 'google', 'microsoft']
|
|
113
|
+
*/
|
|
114
|
+
providers?: ('github' | 'google' | 'microsoft')[] | false;
|
|
115
|
+
/**
|
|
116
|
+
* Show a divider between OAuth and email/password forms.
|
|
117
|
+
* Only visible when providers are enabled.
|
|
118
|
+
* @default true
|
|
119
|
+
*/
|
|
120
|
+
showDivider?: boolean;
|
|
64
121
|
}
|
|
65
122
|
/**
|
|
66
123
|
* Props for the SignUp component
|
|
@@ -72,6 +129,8 @@ interface SignUpProps {
|
|
|
72
129
|
onError?: (error: Error) => void;
|
|
73
130
|
/** Organization slug for registration context */
|
|
74
131
|
orgSlug?: string;
|
|
132
|
+
/** Service slug for registration context (used with orgSlug for tenant attribution) */
|
|
133
|
+
serviceSlug?: string;
|
|
75
134
|
/** Whether to show the "sign in" link */
|
|
76
135
|
showSignIn?: boolean;
|
|
77
136
|
/** Custom class name for the form container */
|
|
@@ -112,23 +171,71 @@ interface ProtectProps {
|
|
|
112
171
|
/** React children to render when access is granted */
|
|
113
172
|
children: React.ReactNode;
|
|
114
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* Supported OAuth providers
|
|
176
|
+
*/
|
|
177
|
+
type SupportedOAuthProvider = 'github' | 'google' | 'microsoft';
|
|
178
|
+
/**
|
|
179
|
+
* Props for the OAuthButton component
|
|
180
|
+
*/
|
|
181
|
+
interface OAuthButtonProps {
|
|
182
|
+
/** OAuth provider to authenticate with */
|
|
183
|
+
provider: SupportedOAuthProvider;
|
|
184
|
+
/** Button content. Defaults to "Continue with {Provider}" */
|
|
185
|
+
children?: React.ReactNode;
|
|
186
|
+
/** Custom class name for the button */
|
|
187
|
+
className?: string;
|
|
188
|
+
/** Callback when OAuth redirect is initiated */
|
|
189
|
+
onRedirect?: () => void;
|
|
190
|
+
/** Whether the button is disabled */
|
|
191
|
+
disabled?: boolean;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Props for the SignedIn component.
|
|
195
|
+
* Renders children only when the user is authenticated.
|
|
196
|
+
*/
|
|
197
|
+
interface SignedInProps {
|
|
198
|
+
/** Content to render when user is signed in */
|
|
199
|
+
children: React.ReactNode;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Props for the SignedOut component.
|
|
203
|
+
* Renders children only when the user is not authenticated.
|
|
204
|
+
*/
|
|
205
|
+
interface SignedOutProps {
|
|
206
|
+
/** Content to render when user is signed out */
|
|
207
|
+
children: React.ReactNode;
|
|
208
|
+
}
|
|
115
209
|
|
|
116
210
|
/**
|
|
117
211
|
* Provider component that wraps your app and provides AuthOS context.
|
|
118
212
|
*
|
|
119
|
-
* @example
|
|
213
|
+
* @example Basic usage
|
|
120
214
|
* ```tsx
|
|
121
|
-
* import { AuthOSProvider } from '@drmhse/authos-react';
|
|
215
|
+
* import { AuthOSProvider, SignIn, SignedOut } from '@drmhse/authos-react';
|
|
122
216
|
*
|
|
123
217
|
* function App() {
|
|
124
218
|
* return (
|
|
125
|
-
* <AuthOSProvider config={{ baseURL: 'https://
|
|
126
|
-
* <
|
|
219
|
+
* <AuthOSProvider config={{ baseURL: 'https://sso.example.com' }}>
|
|
220
|
+
* <SignedOut>
|
|
221
|
+
* <SignIn />
|
|
222
|
+
* </SignedOut>
|
|
127
223
|
* </AuthOSProvider>
|
|
128
224
|
* );
|
|
129
225
|
* }
|
|
130
226
|
* ```
|
|
131
227
|
*
|
|
228
|
+
* @example With OAuth (requires org and service)
|
|
229
|
+
* ```tsx
|
|
230
|
+
* <AuthOSProvider config={{
|
|
231
|
+
* baseURL: 'https://sso.example.com',
|
|
232
|
+
* org: 'my-org',
|
|
233
|
+
* service: 'my-app',
|
|
234
|
+
* }}>
|
|
235
|
+
* <SignIn providers={['github', 'google']} />
|
|
236
|
+
* </AuthOSProvider>
|
|
237
|
+
* ```
|
|
238
|
+
*
|
|
132
239
|
* @example With SSR token (Next.js App Router)
|
|
133
240
|
* ```tsx
|
|
134
241
|
* import { cookies } from 'next/headers';
|
|
@@ -140,7 +247,7 @@ interface ProtectProps {
|
|
|
140
247
|
*
|
|
141
248
|
* return (
|
|
142
249
|
* <AuthOSProvider
|
|
143
|
-
* config={{ baseURL: 'https://
|
|
250
|
+
* config={{ baseURL: 'https://sso.example.com' }}
|
|
144
251
|
* initialSessionToken={token}
|
|
145
252
|
* >
|
|
146
253
|
* {children}
|
|
@@ -203,15 +310,15 @@ declare function useUser(): UserProfile | null;
|
|
|
203
310
|
interface UseOrganizationReturn {
|
|
204
311
|
/** The current active organization */
|
|
205
312
|
organization: Organization | null;
|
|
206
|
-
/** Switch to a different organization by slug */
|
|
313
|
+
/** Switch to a different organization by slug - issues new org-scoped tokens */
|
|
207
314
|
switchOrganization: (slug: string) => Promise<void>;
|
|
208
315
|
}
|
|
209
316
|
/**
|
|
210
317
|
* Hook to access the current organization context and switch between organizations.
|
|
211
318
|
*
|
|
212
|
-
*
|
|
213
|
-
* organization
|
|
214
|
-
*
|
|
319
|
+
* When switching organizations, this hook calls the backend to issue new JWT tokens
|
|
320
|
+
* with the organization context, enabling seamless organization switching without
|
|
321
|
+
* requiring re-authentication.
|
|
215
322
|
*
|
|
216
323
|
* @returns The current organization and a function to switch organizations
|
|
217
324
|
*
|
|
@@ -291,9 +398,10 @@ declare function useAnyPermission(permissions: string[]): boolean;
|
|
|
291
398
|
declare function useAllPermissions(permissions: string[]): boolean;
|
|
292
399
|
|
|
293
400
|
/**
|
|
294
|
-
*
|
|
401
|
+
* SignIn component that handles email/password authentication with MFA support.
|
|
402
|
+
* Optionally displays OAuth provider buttons when `providers` prop is set.
|
|
295
403
|
*
|
|
296
|
-
* @example
|
|
404
|
+
* @example Basic email/password only
|
|
297
405
|
* ```tsx
|
|
298
406
|
* import { SignIn } from '@drmhse/authos-react';
|
|
299
407
|
*
|
|
@@ -306,8 +414,16 @@ declare function useAllPermissions(permissions: string[]): boolean;
|
|
|
306
414
|
* );
|
|
307
415
|
* }
|
|
308
416
|
* ```
|
|
417
|
+
*
|
|
418
|
+
* @example With OAuth providers (requires org/service in provider config)
|
|
419
|
+
* ```tsx
|
|
420
|
+
* <SignIn
|
|
421
|
+
* providers={['github', 'google', 'microsoft']}
|
|
422
|
+
* onSuccess={(user) => router.push('/dashboard')}
|
|
423
|
+
* />
|
|
424
|
+
* ```
|
|
309
425
|
*/
|
|
310
|
-
declare function SignIn({ onSuccess, onError, showForgotPassword, showSignUp, className, }: SignInProps): react_jsx_runtime.JSX.Element;
|
|
426
|
+
declare function SignIn({ onSuccess, onError, showForgotPassword, showSignUp, className, providers, showDivider, }: SignInProps): react_jsx_runtime.JSX.Element;
|
|
311
427
|
|
|
312
428
|
/**
|
|
313
429
|
* Headless SignUp component that handles user registration.
|
|
@@ -326,7 +442,7 @@ declare function SignIn({ onSuccess, onError, showForgotPassword, showSignUp, cl
|
|
|
326
442
|
* }
|
|
327
443
|
* ```
|
|
328
444
|
*/
|
|
329
|
-
declare function SignUp({ onSuccess, onError, orgSlug, showSignIn, className }: SignUpProps): react_jsx_runtime.JSX.Element;
|
|
445
|
+
declare function SignUp({ onSuccess, onError, orgSlug, serviceSlug, showSignIn, className }: SignUpProps): react_jsx_runtime.JSX.Element;
|
|
330
446
|
|
|
331
447
|
/**
|
|
332
448
|
* Component for switching between organizations.
|
|
@@ -395,4 +511,138 @@ declare function UserButton({ className, showEmail, onLogout }: UserButtonProps)
|
|
|
395
511
|
*/
|
|
396
512
|
declare function Protect({ permission, role, fallback, children }: ProtectProps): react_jsx_runtime.JSX.Element;
|
|
397
513
|
|
|
398
|
-
|
|
514
|
+
/**
|
|
515
|
+
* OAuth login button for a specific provider.
|
|
516
|
+
* Redirects the user to the OAuth provider's login page.
|
|
517
|
+
*
|
|
518
|
+
* Requires `org` and `service` to be configured in the AuthOSProvider.
|
|
519
|
+
*
|
|
520
|
+
* @example
|
|
521
|
+
* ```tsx
|
|
522
|
+
* import { OAuthButton } from '@drmhse/authos-react';
|
|
523
|
+
*
|
|
524
|
+
* function LoginPage() {
|
|
525
|
+
* return (
|
|
526
|
+
* <div>
|
|
527
|
+
* <OAuthButton provider="github" />
|
|
528
|
+
* <OAuthButton provider="google">Sign in with Google</OAuthButton>
|
|
529
|
+
* <OAuthButton provider="microsoft" className="btn-microsoft" />
|
|
530
|
+
* </div>
|
|
531
|
+
* );
|
|
532
|
+
* }
|
|
533
|
+
* ```
|
|
534
|
+
*/
|
|
535
|
+
declare function OAuthButton({ provider, children, className, onRedirect, disabled, }: OAuthButtonProps): react_jsx_runtime.JSX.Element;
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* Renders children only when the user is authenticated.
|
|
539
|
+
* Use with SignedOut to create conditional UI based on auth state.
|
|
540
|
+
*
|
|
541
|
+
* @example
|
|
542
|
+
* ```tsx
|
|
543
|
+
* import { SignedIn, SignedOut, UserButton, SignIn } from '@drmhse/authos-react';
|
|
544
|
+
*
|
|
545
|
+
* function Header() {
|
|
546
|
+
* return (
|
|
547
|
+
* <header>
|
|
548
|
+
* <SignedIn>
|
|
549
|
+
* <UserButton />
|
|
550
|
+
* </SignedIn>
|
|
551
|
+
* <SignedOut>
|
|
552
|
+
* <SignIn />
|
|
553
|
+
* </SignedOut>
|
|
554
|
+
* </header>
|
|
555
|
+
* );
|
|
556
|
+
* }
|
|
557
|
+
* ```
|
|
558
|
+
*/
|
|
559
|
+
declare function SignedIn({ children }: SignedInProps): react_jsx_runtime.JSX.Element | null;
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* Renders children only when the user is NOT authenticated.
|
|
563
|
+
* Use with SignedIn to create conditional UI based on auth state.
|
|
564
|
+
*
|
|
565
|
+
* @example
|
|
566
|
+
* ```tsx
|
|
567
|
+
* import { SignedIn, SignedOut, UserButton, SignIn } from '@drmhse/authos-react';
|
|
568
|
+
*
|
|
569
|
+
* function Header() {
|
|
570
|
+
* return (
|
|
571
|
+
* <header>
|
|
572
|
+
* <SignedIn>
|
|
573
|
+
* <UserButton />
|
|
574
|
+
* </SignedIn>
|
|
575
|
+
* <SignedOut>
|
|
576
|
+
* <SignIn />
|
|
577
|
+
* </SignedOut>
|
|
578
|
+
* </header>
|
|
579
|
+
* );
|
|
580
|
+
* }
|
|
581
|
+
* ```
|
|
582
|
+
*/
|
|
583
|
+
declare function SignedOut({ children }: SignedOutProps): react_jsx_runtime.JSX.Element | null;
|
|
584
|
+
|
|
585
|
+
interface MagicLinkSignInProps {
|
|
586
|
+
/** Callback when magic link is successfully sent */
|
|
587
|
+
onSuccess?: () => void;
|
|
588
|
+
/** Callback when sending fails */
|
|
589
|
+
onError?: (error: Error) => void;
|
|
590
|
+
/** Custom class name */
|
|
591
|
+
className?: string;
|
|
592
|
+
/** Show sign in with password link */
|
|
593
|
+
showPasswordSignIn?: boolean;
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* Passwordless sign-in via magic link (email).
|
|
597
|
+
*
|
|
598
|
+
* Sends a one-time login link to the user's email address.
|
|
599
|
+
*
|
|
600
|
+
* @example
|
|
601
|
+
* ```tsx
|
|
602
|
+
* import { MagicLinkSignIn } from '@drmhse/authos-react';
|
|
603
|
+
*
|
|
604
|
+
* function LoginPage() {
|
|
605
|
+
* return (
|
|
606
|
+
* <MagicLinkSignIn
|
|
607
|
+
* onSuccess={() => alert('Check your email!')}
|
|
608
|
+
* onError={(err) => console.error(err)}
|
|
609
|
+
* />
|
|
610
|
+
* );
|
|
611
|
+
* }
|
|
612
|
+
* ```
|
|
613
|
+
*/
|
|
614
|
+
declare function MagicLinkSignIn({ onSuccess, onError, className, showPasswordSignIn, }: MagicLinkSignInProps): react_jsx_runtime.JSX.Element;
|
|
615
|
+
|
|
616
|
+
interface PasskeySignInProps {
|
|
617
|
+
/** Callback when passkey sign-in is successful */
|
|
618
|
+
onSuccess?: () => void;
|
|
619
|
+
/** Callback when sign-in fails */
|
|
620
|
+
onError?: (error: Error) => void;
|
|
621
|
+
/** Custom class name */
|
|
622
|
+
className?: string;
|
|
623
|
+
/** Show sign in with password link */
|
|
624
|
+
showPasswordSignIn?: boolean;
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* Passkey (WebAuthn) sign-in component.
|
|
628
|
+
*
|
|
629
|
+
* Uses the Web Authentication API for passwordless authentication
|
|
630
|
+
* via biometrics, security keys, or platform authenticators.
|
|
631
|
+
*
|
|
632
|
+
* @example
|
|
633
|
+
* ```tsx
|
|
634
|
+
* import { PasskeySignIn } from '@drmhse/authos-react';
|
|
635
|
+
*
|
|
636
|
+
* function LoginPage() {
|
|
637
|
+
* return (
|
|
638
|
+
* <PasskeySignIn
|
|
639
|
+
* onSuccess={() => router.push('/dashboard')}
|
|
640
|
+
* onError={(err) => console.error(err)}
|
|
641
|
+
* />
|
|
642
|
+
* );
|
|
643
|
+
* }
|
|
644
|
+
* ```
|
|
645
|
+
*/
|
|
646
|
+
declare function PasskeySignIn({ onSuccess, onError, className, showPasswordSignIn, }: PasskeySignInProps): react_jsx_runtime.JSX.Element;
|
|
647
|
+
|
|
648
|
+
export { type AuthOSConfig, type AuthOSContextState, AuthOSProvider, type AuthOSProviderProps, MagicLinkSignIn, type MagicLinkSignInProps, OAuthButton, type OAuthButtonProps, OrganizationSwitcher, type OrganizationSwitcherProps, PasskeySignIn, type PasskeySignInProps, Protect, type ProtectProps, SignIn, type SignInProps, SignUp, type SignUpProps, SignedIn, type SignedInProps, SignedOut, type SignedOutProps, type SupportedOAuthProvider, UserButton, type UserButtonProps, useAllPermissions, useAnyPermission, useAuthOS, useAuthOSContext, useOrganization, usePermission, useUser };
|