@drmhse/authos-react 0.1.0
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 +372 -0
- package/dist/index.d.ts +372 -0
- package/dist/index.js +555 -0
- package/dist/index.mjs +530 -0
- package/dist/nextjs.d.mts +146 -0
- package/dist/nextjs.d.ts +146 -0
- package/dist/nextjs.js +5878 -0
- package/dist/nextjs.mjs +5873 -0
- package/package.json +76 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as _drmhse_sso_sdk from '@drmhse/sso-sdk';
|
|
3
|
+
import { SsoClientOptions, SsoClient, UserProfile, Organization } from '@drmhse/sso-sdk';
|
|
4
|
+
export { AuthErrorCodes, Organization, SsoApiError, SsoClient, SsoClientOptions, UserProfile } from '@drmhse/sso-sdk';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Configuration options for the AuthOS React provider
|
|
8
|
+
*/
|
|
9
|
+
interface AuthOSProviderProps {
|
|
10
|
+
/**
|
|
11
|
+
* SDK configuration options
|
|
12
|
+
*/
|
|
13
|
+
config: SsoClientOptions;
|
|
14
|
+
/**
|
|
15
|
+
* React children
|
|
16
|
+
*/
|
|
17
|
+
children: React.ReactNode;
|
|
18
|
+
/**
|
|
19
|
+
* Optional: Provide an existing SsoClient instance instead of creating a new one
|
|
20
|
+
*/
|
|
21
|
+
client?: SsoClient;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Authentication context state
|
|
25
|
+
*/
|
|
26
|
+
interface AuthOSContextState {
|
|
27
|
+
/** The underlying SDK client instance */
|
|
28
|
+
client: SsoClient;
|
|
29
|
+
/** Current authenticated user, or null if not authenticated */
|
|
30
|
+
user: UserProfile | null;
|
|
31
|
+
/** Whether the user is authenticated */
|
|
32
|
+
isAuthenticated: boolean;
|
|
33
|
+
/** Whether the initial auth check is still loading */
|
|
34
|
+
isLoading: boolean;
|
|
35
|
+
/** Current active organization context */
|
|
36
|
+
organization: Organization | null;
|
|
37
|
+
/** Set the current user (internal use) */
|
|
38
|
+
setUser: (user: UserProfile | null) => void;
|
|
39
|
+
/** Set the current organization (internal use) */
|
|
40
|
+
setOrganization: (org: Organization | null) => void;
|
|
41
|
+
/** Refresh the current user data from the server */
|
|
42
|
+
refreshUser: () => Promise<void>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Props for the SignIn component
|
|
46
|
+
*/
|
|
47
|
+
interface SignInProps {
|
|
48
|
+
/** Callback when sign-in is successful */
|
|
49
|
+
onSuccess?: (user: UserProfile) => void;
|
|
50
|
+
/** Callback when sign-in fails */
|
|
51
|
+
onError?: (error: Error) => void;
|
|
52
|
+
/** Whether to show the "forgot password" link */
|
|
53
|
+
showForgotPassword?: boolean;
|
|
54
|
+
/** Whether to show the "sign up" link */
|
|
55
|
+
showSignUp?: boolean;
|
|
56
|
+
/** Custom class name for the form container */
|
|
57
|
+
className?: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Props for the SignUp component
|
|
61
|
+
*/
|
|
62
|
+
interface SignUpProps {
|
|
63
|
+
/** Callback when sign-up is successful */
|
|
64
|
+
onSuccess?: () => void;
|
|
65
|
+
/** Callback when sign-up fails */
|
|
66
|
+
onError?: (error: Error) => void;
|
|
67
|
+
/** Organization slug for registration context */
|
|
68
|
+
orgSlug?: string;
|
|
69
|
+
/** Whether to show the "sign in" link */
|
|
70
|
+
showSignIn?: boolean;
|
|
71
|
+
/** Custom class name for the form container */
|
|
72
|
+
className?: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Props for the OrganizationSwitcher component
|
|
76
|
+
*/
|
|
77
|
+
interface OrganizationSwitcherProps {
|
|
78
|
+
/** Callback when organization is switched */
|
|
79
|
+
onSwitch?: (org: Organization) => void;
|
|
80
|
+
/** Custom class name for the switcher container */
|
|
81
|
+
className?: string;
|
|
82
|
+
/** Render prop for custom organization item rendering */
|
|
83
|
+
renderItem?: (org: Organization, isActive: boolean) => React.ReactNode;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Props for the UserButton component
|
|
87
|
+
*/
|
|
88
|
+
interface UserButtonProps {
|
|
89
|
+
/** Custom class name for the button container */
|
|
90
|
+
className?: string;
|
|
91
|
+
/** Whether to show the user's email */
|
|
92
|
+
showEmail?: boolean;
|
|
93
|
+
/** Callback after successful logout */
|
|
94
|
+
onLogout?: () => void;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Props for the Protect component
|
|
98
|
+
*/
|
|
99
|
+
interface ProtectProps {
|
|
100
|
+
/** Required permission to access children */
|
|
101
|
+
permission?: string;
|
|
102
|
+
/** Required role to access children */
|
|
103
|
+
role?: 'owner' | 'admin' | 'member';
|
|
104
|
+
/** Fallback content when access is denied */
|
|
105
|
+
fallback?: React.ReactNode;
|
|
106
|
+
/** React children to render when access is granted */
|
|
107
|
+
children: React.ReactNode;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Provider component that wraps your app and provides AuthOS context.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```tsx
|
|
115
|
+
* import { AuthOSProvider } from '@drmhse/authos-react';
|
|
116
|
+
*
|
|
117
|
+
* function App() {
|
|
118
|
+
* return (
|
|
119
|
+
* <AuthOSProvider config={{ baseURL: 'https://auth.example.com' }}>
|
|
120
|
+
* <YourApp />
|
|
121
|
+
* </AuthOSProvider>
|
|
122
|
+
* );
|
|
123
|
+
* }
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
declare function AuthOSProvider({ config, children, client: externalClient }: AuthOSProviderProps): react_jsx_runtime.JSX.Element;
|
|
127
|
+
/**
|
|
128
|
+
* Hook to access the AuthOS context.
|
|
129
|
+
* Must be used within an AuthOSProvider.
|
|
130
|
+
*
|
|
131
|
+
* @throws Error if used outside of AuthOSProvider
|
|
132
|
+
*/
|
|
133
|
+
declare function useAuthOSContext(): AuthOSContextState;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Hook to access the AuthOS client and loading status.
|
|
137
|
+
*
|
|
138
|
+
* @returns The SDK client instance and loading state
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```tsx
|
|
142
|
+
* function MyComponent() {
|
|
143
|
+
* const { client, isLoading } = useAuthOS();
|
|
144
|
+
*
|
|
145
|
+
* if (isLoading) return <div>Loading...</div>;
|
|
146
|
+
*
|
|
147
|
+
* const handleLogin = async () => {
|
|
148
|
+
* await client.auth.login({ email, password });
|
|
149
|
+
* };
|
|
150
|
+
* }
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
declare function useAuthOS(): {
|
|
154
|
+
client: _drmhse_sso_sdk.SsoClient;
|
|
155
|
+
isLoading: boolean;
|
|
156
|
+
isAuthenticated: boolean;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Hook to access the current authenticated user.
|
|
161
|
+
*
|
|
162
|
+
* @returns The current user profile or null if not authenticated
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```tsx
|
|
166
|
+
* function ProfilePage() {
|
|
167
|
+
* const user = useUser();
|
|
168
|
+
*
|
|
169
|
+
* if (!user) return <div>Please sign in</div>;
|
|
170
|
+
*
|
|
171
|
+
* return <div>Welcome, {user.email}!</div>;
|
|
172
|
+
* }
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
declare function useUser(): UserProfile | null;
|
|
176
|
+
|
|
177
|
+
interface UseOrganizationReturn {
|
|
178
|
+
/** The current active organization */
|
|
179
|
+
organization: Organization | null;
|
|
180
|
+
/** Switch to a different organization by slug */
|
|
181
|
+
switchOrganization: (slug: string) => Promise<void>;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Hook to access the current organization context and switch between organizations.
|
|
185
|
+
*
|
|
186
|
+
* Note: Organization switching sets the local context. For full token-scoped
|
|
187
|
+
* organization switching, users should re-authenticate through the OAuth flow
|
|
188
|
+
* with the organization parameter.
|
|
189
|
+
*
|
|
190
|
+
* @returns The current organization and a function to switch organizations
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```tsx
|
|
194
|
+
* function OrgSelector() {
|
|
195
|
+
* const { organization, switchOrganization } = useOrganization();
|
|
196
|
+
*
|
|
197
|
+
* return (
|
|
198
|
+
* <div>
|
|
199
|
+
* <p>Current org: {organization?.name}</p>
|
|
200
|
+
* <button onClick={() => switchOrganization('other-org')}>
|
|
201
|
+
* Switch to Other Org
|
|
202
|
+
* </button>
|
|
203
|
+
* </div>
|
|
204
|
+
* );
|
|
205
|
+
* }
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
declare function useOrganization(): UseOrganizationReturn;
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Hook to check if the current user has a specific permission.
|
|
212
|
+
*
|
|
213
|
+
* @param permission - The permission string to check for
|
|
214
|
+
* @returns True if the user has the permission, false otherwise
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* ```tsx
|
|
218
|
+
* function AdminPanel() {
|
|
219
|
+
* const canManageUsers = usePermission('users:manage');
|
|
220
|
+
*
|
|
221
|
+
* if (!canManageUsers) {
|
|
222
|
+
* return <div>Access denied</div>;
|
|
223
|
+
* }
|
|
224
|
+
*
|
|
225
|
+
* return <div>Admin Panel Content</div>;
|
|
226
|
+
* }
|
|
227
|
+
* ```
|
|
228
|
+
*/
|
|
229
|
+
declare function usePermission(permission: string): boolean;
|
|
230
|
+
/**
|
|
231
|
+
* Hook to check if the current user has any of the specified permissions.
|
|
232
|
+
*
|
|
233
|
+
* @param permissions - Array of permission strings to check
|
|
234
|
+
* @returns True if the user has at least one of the permissions
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* ```tsx
|
|
238
|
+
* function EditButton() {
|
|
239
|
+
* const canEdit = useAnyPermission(['posts:edit', 'posts:manage']);
|
|
240
|
+
*
|
|
241
|
+
* if (!canEdit) return null;
|
|
242
|
+
*
|
|
243
|
+
* return <button>Edit</button>;
|
|
244
|
+
* }
|
|
245
|
+
* ```
|
|
246
|
+
*/
|
|
247
|
+
declare function useAnyPermission(permissions: string[]): boolean;
|
|
248
|
+
/**
|
|
249
|
+
* Hook to check if the current user has all of the specified permissions.
|
|
250
|
+
*
|
|
251
|
+
* @param permissions - Array of permission strings that are all required
|
|
252
|
+
* @returns True only if the user has all of the permissions
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* ```tsx
|
|
256
|
+
* function AdvancedSettings() {
|
|
257
|
+
* const hasAccess = useAllPermissions(['settings:view', 'settings:edit']);
|
|
258
|
+
*
|
|
259
|
+
* if (!hasAccess) return <div>Insufficient permissions</div>;
|
|
260
|
+
*
|
|
261
|
+
* return <SettingsForm />;
|
|
262
|
+
* }
|
|
263
|
+
* ```
|
|
264
|
+
*/
|
|
265
|
+
declare function useAllPermissions(permissions: string[]): boolean;
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Headless SignIn component that handles email/password authentication with MFA support.
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* ```tsx
|
|
272
|
+
* import { SignIn } from '@drmhse/authos-react';
|
|
273
|
+
*
|
|
274
|
+
* function LoginPage() {
|
|
275
|
+
* return (
|
|
276
|
+
* <SignIn
|
|
277
|
+
* onSuccess={(user) => console.log('Logged in:', user)}
|
|
278
|
+
* onError={(error) => console.error('Login failed:', error)}
|
|
279
|
+
* />
|
|
280
|
+
* );
|
|
281
|
+
* }
|
|
282
|
+
* ```
|
|
283
|
+
*/
|
|
284
|
+
declare function SignIn({ onSuccess, onError, showForgotPassword, showSignUp, className, }: SignInProps): react_jsx_runtime.JSX.Element;
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Headless SignUp component that handles user registration.
|
|
288
|
+
*
|
|
289
|
+
* @example
|
|
290
|
+
* ```tsx
|
|
291
|
+
* import { SignUp } from '@drmhse/authos-react';
|
|
292
|
+
*
|
|
293
|
+
* function RegisterPage() {
|
|
294
|
+
* return (
|
|
295
|
+
* <SignUp
|
|
296
|
+
* onSuccess={() => console.log('Registration successful!')}
|
|
297
|
+
* onError={(error) => console.error('Registration failed:', error)}
|
|
298
|
+
* />
|
|
299
|
+
* );
|
|
300
|
+
* }
|
|
301
|
+
* ```
|
|
302
|
+
*/
|
|
303
|
+
declare function SignUp({ onSuccess, onError, orgSlug, showSignIn, className }: SignUpProps): react_jsx_runtime.JSX.Element;
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Component for switching between organizations.
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
* ```tsx
|
|
310
|
+
* import { OrganizationSwitcher } from '@drmhse/authos-react';
|
|
311
|
+
*
|
|
312
|
+
* function Header() {
|
|
313
|
+
* return (
|
|
314
|
+
* <OrganizationSwitcher
|
|
315
|
+
* onSwitch={(org) => console.log('Switched to:', org.name)}
|
|
316
|
+
* />
|
|
317
|
+
* );
|
|
318
|
+
* }
|
|
319
|
+
* ```
|
|
320
|
+
*/
|
|
321
|
+
declare function OrganizationSwitcher({ onSwitch, className, renderItem }: OrganizationSwitcherProps): react_jsx_runtime.JSX.Element | null;
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Component for displaying user info and handling logout.
|
|
325
|
+
*
|
|
326
|
+
* @example
|
|
327
|
+
* ```tsx
|
|
328
|
+
* import { UserButton } from '@drmhse/authos-react';
|
|
329
|
+
*
|
|
330
|
+
* function Header() {
|
|
331
|
+
* return (
|
|
332
|
+
* <UserButton
|
|
333
|
+
* showEmail
|
|
334
|
+
* onLogout={() => window.location.href = '/'}
|
|
335
|
+
* />
|
|
336
|
+
* );
|
|
337
|
+
* }
|
|
338
|
+
* ```
|
|
339
|
+
*/
|
|
340
|
+
declare function UserButton({ className, showEmail, onLogout }: UserButtonProps): react_jsx_runtime.JSX.Element;
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Component that conditionally renders children based on permission or role.
|
|
344
|
+
*
|
|
345
|
+
* @example
|
|
346
|
+
* ```tsx
|
|
347
|
+
* import { Protect } from '@drmhse/authos-react';
|
|
348
|
+
*
|
|
349
|
+
* function AdminPage() {
|
|
350
|
+
* return (
|
|
351
|
+
* <Protect
|
|
352
|
+
* permission="admin:access"
|
|
353
|
+
* fallback={<div>Access denied</div>}
|
|
354
|
+
* >
|
|
355
|
+
* <AdminDashboard />
|
|
356
|
+
* </Protect>
|
|
357
|
+
* );
|
|
358
|
+
* }
|
|
359
|
+
*
|
|
360
|
+
* // Or using role
|
|
361
|
+
* function OwnerSettings() {
|
|
362
|
+
* return (
|
|
363
|
+
* <Protect role="owner">
|
|
364
|
+
* <DangerZone />
|
|
365
|
+
* </Protect>
|
|
366
|
+
* );
|
|
367
|
+
* }
|
|
368
|
+
* ```
|
|
369
|
+
*/
|
|
370
|
+
declare function Protect({ permission, role, fallback, children }: ProtectProps): react_jsx_runtime.JSX.Element;
|
|
371
|
+
|
|
372
|
+
export { type AuthOSContextState, AuthOSProvider, type AuthOSProviderProps, OrganizationSwitcher, type OrganizationSwitcherProps, Protect, type ProtectProps, SignIn, type SignInProps, SignUp, type SignUpProps, UserButton, type UserButtonProps, useAllPermissions, useAnyPermission, useAuthOS, useAuthOSContext, useOrganization, usePermission, useUser };
|