@drmhse/authos-react 0.1.2 → 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/README.md +263 -147
- package/dist/index.d.mts +263 -15
- package/dist/index.d.ts +263 -15
- package/dist/index.js +277 -43
- package/dist/index.mjs +274 -45
- 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
|
|
@@ -112,23 +169,71 @@ interface ProtectProps {
|
|
|
112
169
|
/** React children to render when access is granted */
|
|
113
170
|
children: React.ReactNode;
|
|
114
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* Supported OAuth providers
|
|
174
|
+
*/
|
|
175
|
+
type SupportedOAuthProvider = 'github' | 'google' | 'microsoft';
|
|
176
|
+
/**
|
|
177
|
+
* Props for the OAuthButton component
|
|
178
|
+
*/
|
|
179
|
+
interface OAuthButtonProps {
|
|
180
|
+
/** OAuth provider to authenticate with */
|
|
181
|
+
provider: SupportedOAuthProvider;
|
|
182
|
+
/** Button content. Defaults to "Continue with {Provider}" */
|
|
183
|
+
children?: React.ReactNode;
|
|
184
|
+
/** Custom class name for the button */
|
|
185
|
+
className?: string;
|
|
186
|
+
/** Callback when OAuth redirect is initiated */
|
|
187
|
+
onRedirect?: () => void;
|
|
188
|
+
/** Whether the button is disabled */
|
|
189
|
+
disabled?: boolean;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Props for the SignedIn component.
|
|
193
|
+
* Renders children only when the user is authenticated.
|
|
194
|
+
*/
|
|
195
|
+
interface SignedInProps {
|
|
196
|
+
/** Content to render when user is signed in */
|
|
197
|
+
children: React.ReactNode;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Props for the SignedOut component.
|
|
201
|
+
* Renders children only when the user is not authenticated.
|
|
202
|
+
*/
|
|
203
|
+
interface SignedOutProps {
|
|
204
|
+
/** Content to render when user is signed out */
|
|
205
|
+
children: React.ReactNode;
|
|
206
|
+
}
|
|
115
207
|
|
|
116
208
|
/**
|
|
117
209
|
* Provider component that wraps your app and provides AuthOS context.
|
|
118
210
|
*
|
|
119
|
-
* @example
|
|
211
|
+
* @example Basic usage
|
|
120
212
|
* ```tsx
|
|
121
|
-
* import { AuthOSProvider } from '@drmhse/authos-react';
|
|
213
|
+
* import { AuthOSProvider, SignIn, SignedOut } from '@drmhse/authos-react';
|
|
122
214
|
*
|
|
123
215
|
* function App() {
|
|
124
216
|
* return (
|
|
125
|
-
* <AuthOSProvider config={{ baseURL: 'https://
|
|
126
|
-
* <
|
|
217
|
+
* <AuthOSProvider config={{ baseURL: 'https://sso.example.com' }}>
|
|
218
|
+
* <SignedOut>
|
|
219
|
+
* <SignIn />
|
|
220
|
+
* </SignedOut>
|
|
127
221
|
* </AuthOSProvider>
|
|
128
222
|
* );
|
|
129
223
|
* }
|
|
130
224
|
* ```
|
|
131
225
|
*
|
|
226
|
+
* @example With OAuth (requires org and service)
|
|
227
|
+
* ```tsx
|
|
228
|
+
* <AuthOSProvider config={{
|
|
229
|
+
* baseURL: 'https://sso.example.com',
|
|
230
|
+
* org: 'my-org',
|
|
231
|
+
* service: 'my-app',
|
|
232
|
+
* }}>
|
|
233
|
+
* <SignIn providers={['github', 'google']} />
|
|
234
|
+
* </AuthOSProvider>
|
|
235
|
+
* ```
|
|
236
|
+
*
|
|
132
237
|
* @example With SSR token (Next.js App Router)
|
|
133
238
|
* ```tsx
|
|
134
239
|
* import { cookies } from 'next/headers';
|
|
@@ -140,7 +245,7 @@ interface ProtectProps {
|
|
|
140
245
|
*
|
|
141
246
|
* return (
|
|
142
247
|
* <AuthOSProvider
|
|
143
|
-
* config={{ baseURL: 'https://
|
|
248
|
+
* config={{ baseURL: 'https://sso.example.com' }}
|
|
144
249
|
* initialSessionToken={token}
|
|
145
250
|
* >
|
|
146
251
|
* {children}
|
|
@@ -203,15 +308,15 @@ declare function useUser(): UserProfile | null;
|
|
|
203
308
|
interface UseOrganizationReturn {
|
|
204
309
|
/** The current active organization */
|
|
205
310
|
organization: Organization | null;
|
|
206
|
-
/** Switch to a different organization by slug */
|
|
311
|
+
/** Switch to a different organization by slug - issues new org-scoped tokens */
|
|
207
312
|
switchOrganization: (slug: string) => Promise<void>;
|
|
208
313
|
}
|
|
209
314
|
/**
|
|
210
315
|
* Hook to access the current organization context and switch between organizations.
|
|
211
316
|
*
|
|
212
|
-
*
|
|
213
|
-
* organization
|
|
214
|
-
*
|
|
317
|
+
* When switching organizations, this hook calls the backend to issue new JWT tokens
|
|
318
|
+
* with the organization context, enabling seamless organization switching without
|
|
319
|
+
* requiring re-authentication.
|
|
215
320
|
*
|
|
216
321
|
* @returns The current organization and a function to switch organizations
|
|
217
322
|
*
|
|
@@ -291,9 +396,10 @@ declare function useAnyPermission(permissions: string[]): boolean;
|
|
|
291
396
|
declare function useAllPermissions(permissions: string[]): boolean;
|
|
292
397
|
|
|
293
398
|
/**
|
|
294
|
-
*
|
|
399
|
+
* SignIn component that handles email/password authentication with MFA support.
|
|
400
|
+
* Optionally displays OAuth provider buttons when `providers` prop is set.
|
|
295
401
|
*
|
|
296
|
-
* @example
|
|
402
|
+
* @example Basic email/password only
|
|
297
403
|
* ```tsx
|
|
298
404
|
* import { SignIn } from '@drmhse/authos-react';
|
|
299
405
|
*
|
|
@@ -306,8 +412,16 @@ declare function useAllPermissions(permissions: string[]): boolean;
|
|
|
306
412
|
* );
|
|
307
413
|
* }
|
|
308
414
|
* ```
|
|
415
|
+
*
|
|
416
|
+
* @example With OAuth providers (requires org/service in provider config)
|
|
417
|
+
* ```tsx
|
|
418
|
+
* <SignIn
|
|
419
|
+
* providers={['github', 'google', 'microsoft']}
|
|
420
|
+
* onSuccess={(user) => router.push('/dashboard')}
|
|
421
|
+
* />
|
|
422
|
+
* ```
|
|
309
423
|
*/
|
|
310
|
-
declare function SignIn({ onSuccess, onError, showForgotPassword, showSignUp, className, }: SignInProps): react_jsx_runtime.JSX.Element;
|
|
424
|
+
declare function SignIn({ onSuccess, onError, showForgotPassword, showSignUp, className, providers, showDivider, }: SignInProps): react_jsx_runtime.JSX.Element;
|
|
311
425
|
|
|
312
426
|
/**
|
|
313
427
|
* Headless SignUp component that handles user registration.
|
|
@@ -395,4 +509,138 @@ declare function UserButton({ className, showEmail, onLogout }: UserButtonProps)
|
|
|
395
509
|
*/
|
|
396
510
|
declare function Protect({ permission, role, fallback, children }: ProtectProps): react_jsx_runtime.JSX.Element;
|
|
397
511
|
|
|
398
|
-
|
|
512
|
+
/**
|
|
513
|
+
* OAuth login button for a specific provider.
|
|
514
|
+
* Redirects the user to the OAuth provider's login page.
|
|
515
|
+
*
|
|
516
|
+
* Requires `org` and `service` to be configured in the AuthOSProvider.
|
|
517
|
+
*
|
|
518
|
+
* @example
|
|
519
|
+
* ```tsx
|
|
520
|
+
* import { OAuthButton } from '@drmhse/authos-react';
|
|
521
|
+
*
|
|
522
|
+
* function LoginPage() {
|
|
523
|
+
* return (
|
|
524
|
+
* <div>
|
|
525
|
+
* <OAuthButton provider="github" />
|
|
526
|
+
* <OAuthButton provider="google">Sign in with Google</OAuthButton>
|
|
527
|
+
* <OAuthButton provider="microsoft" className="btn-microsoft" />
|
|
528
|
+
* </div>
|
|
529
|
+
* );
|
|
530
|
+
* }
|
|
531
|
+
* ```
|
|
532
|
+
*/
|
|
533
|
+
declare function OAuthButton({ provider, children, className, onRedirect, disabled, }: OAuthButtonProps): react_jsx_runtime.JSX.Element;
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* Renders children only when the user is authenticated.
|
|
537
|
+
* Use with SignedOut to create conditional UI based on auth state.
|
|
538
|
+
*
|
|
539
|
+
* @example
|
|
540
|
+
* ```tsx
|
|
541
|
+
* import { SignedIn, SignedOut, UserButton, SignIn } from '@drmhse/authos-react';
|
|
542
|
+
*
|
|
543
|
+
* function Header() {
|
|
544
|
+
* return (
|
|
545
|
+
* <header>
|
|
546
|
+
* <SignedIn>
|
|
547
|
+
* <UserButton />
|
|
548
|
+
* </SignedIn>
|
|
549
|
+
* <SignedOut>
|
|
550
|
+
* <SignIn />
|
|
551
|
+
* </SignedOut>
|
|
552
|
+
* </header>
|
|
553
|
+
* );
|
|
554
|
+
* }
|
|
555
|
+
* ```
|
|
556
|
+
*/
|
|
557
|
+
declare function SignedIn({ children }: SignedInProps): react_jsx_runtime.JSX.Element | null;
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* Renders children only when the user is NOT authenticated.
|
|
561
|
+
* Use with SignedIn to create conditional UI based on auth state.
|
|
562
|
+
*
|
|
563
|
+
* @example
|
|
564
|
+
* ```tsx
|
|
565
|
+
* import { SignedIn, SignedOut, UserButton, SignIn } from '@drmhse/authos-react';
|
|
566
|
+
*
|
|
567
|
+
* function Header() {
|
|
568
|
+
* return (
|
|
569
|
+
* <header>
|
|
570
|
+
* <SignedIn>
|
|
571
|
+
* <UserButton />
|
|
572
|
+
* </SignedIn>
|
|
573
|
+
* <SignedOut>
|
|
574
|
+
* <SignIn />
|
|
575
|
+
* </SignedOut>
|
|
576
|
+
* </header>
|
|
577
|
+
* );
|
|
578
|
+
* }
|
|
579
|
+
* ```
|
|
580
|
+
*/
|
|
581
|
+
declare function SignedOut({ children }: SignedOutProps): react_jsx_runtime.JSX.Element | null;
|
|
582
|
+
|
|
583
|
+
interface MagicLinkSignInProps {
|
|
584
|
+
/** Callback when magic link is successfully sent */
|
|
585
|
+
onSuccess?: () => void;
|
|
586
|
+
/** Callback when sending fails */
|
|
587
|
+
onError?: (error: Error) => void;
|
|
588
|
+
/** Custom class name */
|
|
589
|
+
className?: string;
|
|
590
|
+
/** Show sign in with password link */
|
|
591
|
+
showPasswordSignIn?: boolean;
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* Passwordless sign-in via magic link (email).
|
|
595
|
+
*
|
|
596
|
+
* Sends a one-time login link to the user's email address.
|
|
597
|
+
*
|
|
598
|
+
* @example
|
|
599
|
+
* ```tsx
|
|
600
|
+
* import { MagicLinkSignIn } from '@drmhse/authos-react';
|
|
601
|
+
*
|
|
602
|
+
* function LoginPage() {
|
|
603
|
+
* return (
|
|
604
|
+
* <MagicLinkSignIn
|
|
605
|
+
* onSuccess={() => alert('Check your email!')}
|
|
606
|
+
* onError={(err) => console.error(err)}
|
|
607
|
+
* />
|
|
608
|
+
* );
|
|
609
|
+
* }
|
|
610
|
+
* ```
|
|
611
|
+
*/
|
|
612
|
+
declare function MagicLinkSignIn({ onSuccess, onError, className, showPasswordSignIn, }: MagicLinkSignInProps): react_jsx_runtime.JSX.Element;
|
|
613
|
+
|
|
614
|
+
interface PasskeySignInProps {
|
|
615
|
+
/** Callback when passkey sign-in is successful */
|
|
616
|
+
onSuccess?: () => void;
|
|
617
|
+
/** Callback when sign-in fails */
|
|
618
|
+
onError?: (error: Error) => void;
|
|
619
|
+
/** Custom class name */
|
|
620
|
+
className?: string;
|
|
621
|
+
/** Show sign in with password link */
|
|
622
|
+
showPasswordSignIn?: boolean;
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* Passkey (WebAuthn) sign-in component.
|
|
626
|
+
*
|
|
627
|
+
* Uses the Web Authentication API for passwordless authentication
|
|
628
|
+
* via biometrics, security keys, or platform authenticators.
|
|
629
|
+
*
|
|
630
|
+
* @example
|
|
631
|
+
* ```tsx
|
|
632
|
+
* import { PasskeySignIn } from '@drmhse/authos-react';
|
|
633
|
+
*
|
|
634
|
+
* function LoginPage() {
|
|
635
|
+
* return (
|
|
636
|
+
* <PasskeySignIn
|
|
637
|
+
* onSuccess={() => router.push('/dashboard')}
|
|
638
|
+
* onError={(err) => console.error(err)}
|
|
639
|
+
* />
|
|
640
|
+
* );
|
|
641
|
+
* }
|
|
642
|
+
* ```
|
|
643
|
+
*/
|
|
644
|
+
declare function PasskeySignIn({ onSuccess, onError, className, showPasswordSignIn, }: PasskeySignInProps): react_jsx_runtime.JSX.Element;
|
|
645
|
+
|
|
646
|
+
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 };
|