authvital-sdk 0.1.1-dev.3.cefb119.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/README.md +657 -0
- package/dist/chunk-ETJ5ICJ7.mjs +412 -0
- package/dist/chunk-FXVD4Y5G.js +412 -0
- package/dist/chunk-JNEJMHGA.mjs +235 -0
- package/dist/chunk-JPODZIZT.mjs +95 -0
- package/dist/chunk-QPYBK2J4.js +235 -0
- package/dist/chunk-R4OHZZQP.js +95 -0
- package/dist/index.d.mts +615 -0
- package/dist/index.d.ts +615 -0
- package/dist/index.js +1299 -0
- package/dist/index.mjs +1299 -0
- package/dist/invitations-EFJA5C6L.mjs +22 -0
- package/dist/invitations-LZHJ3AZY.js +22 -0
- package/dist/oauth-K7E7OCWI.js +34 -0
- package/dist/oauth-UAFXEKZ7.mjs +34 -0
- package/dist/server.d.mts +2656 -0
- package/dist/server.d.ts +2656 -0
- package/dist/server.js +2915 -0
- package/dist/server.mjs +2915 -0
- package/dist/webhook-router-DdfXLtHa.d.mts +461 -0
- package/dist/webhook-router-DdfXLtHa.d.ts +461 -0
- package/package.json +71 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,615 @@
|
|
|
1
|
+
import { ReactNode, CSSProperties } from 'react';
|
|
2
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
|
+
export { o as AppAccessDeactivatedEvent, D as AppAccessEventHandler, A as AppAccessGrantedEvent, n as AppAccessRevokedEvent, p as AppAccessRoleChangedEvent, y as AuthVitalEventHandler, K as IAppAccessEventHandler, F as IAuthVitalEventHandler, G as IInviteEventHandler, N as ILicenseEventHandler, J as IMemberEventHandler, H as ISubjectEventHandler, b as InviteAcceptedEvent, I as InviteCreatedEvent, c as InviteDeletedEvent, z as InviteEventHandler, d as InviteExpiredEvent, L as LicenseAssignedEvent, r as LicenseChangedEvent, E as LicenseEventHandler, q as LicenseRevokedEvent, m as MemberActivatedEvent, C as MemberEventHandler, M as MemberJoinedEvent, j as MemberLeftEvent, k as MemberRoleChangedEvent, l as MemberSuspendedEvent, x as SYNC_EVENT_TYPES, f as SubjectCreatedEvent, e as SubjectData, i as SubjectDeactivatedEvent, h as SubjectDeletedEvent, B as SubjectEventHandler, g as SubjectUpdatedEvent, S as SyncEvent, a as SyncEventType, W as WebhookRouter, O as WebhookRouterOptions, P as WebhookVerifier, Q as WebhookVerifierOptions, v as isAppAccessEvent, s as isInviteEvent, w as isLicenseEvent, u as isMemberEvent, t as isSubjectEvent } from './webhook-router-DdfXLtHa.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @authvital/sdk - Client-Side Types
|
|
7
|
+
*
|
|
8
|
+
* Type definitions for React components and browser-side SDK.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
interface AuthVitalProviderProps {
|
|
12
|
+
/** OAuth Client ID from AuthVital admin panel */
|
|
13
|
+
clientId: string;
|
|
14
|
+
/** AuthVital server URL (e.g., http://localhost:3000) */
|
|
15
|
+
authVitalHost: string;
|
|
16
|
+
/** Redirect after successful sign-in */
|
|
17
|
+
afterSignInUrl?: string;
|
|
18
|
+
/** Redirect after successful sign-up */
|
|
19
|
+
afterSignUpUrl?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Initial user data (from your server after JWT verification).
|
|
22
|
+
* Your server should use `getCurrentUser()` from the server SDK to verify the JWT,
|
|
23
|
+
* then pass the user data here.
|
|
24
|
+
*/
|
|
25
|
+
initialUser?: AuthVitalUser | null;
|
|
26
|
+
/**
|
|
27
|
+
* Initial tenants data (from your server after JWT verification).
|
|
28
|
+
*/
|
|
29
|
+
initialTenants?: AuthVitalTenant[];
|
|
30
|
+
/** Children */
|
|
31
|
+
children: ReactNode;
|
|
32
|
+
}
|
|
33
|
+
interface AuthVitalUser {
|
|
34
|
+
id: string;
|
|
35
|
+
email: string | null;
|
|
36
|
+
givenName: string | null;
|
|
37
|
+
familyName: string | null;
|
|
38
|
+
fullName: string | null;
|
|
39
|
+
imageUrl?: string | null;
|
|
40
|
+
isAnonymous: boolean;
|
|
41
|
+
createdAt?: string;
|
|
42
|
+
updatedAt?: string;
|
|
43
|
+
}
|
|
44
|
+
interface AuthVitalTenant {
|
|
45
|
+
id: string;
|
|
46
|
+
name: string;
|
|
47
|
+
slug: string;
|
|
48
|
+
imageUrl?: string | null;
|
|
49
|
+
role: string;
|
|
50
|
+
}
|
|
51
|
+
interface AuthVitalMembership {
|
|
52
|
+
id: string;
|
|
53
|
+
tenant: AuthVitalTenant;
|
|
54
|
+
role: string;
|
|
55
|
+
joinedAt: string;
|
|
56
|
+
}
|
|
57
|
+
interface AuthContextValue {
|
|
58
|
+
/** Whether user is authenticated */
|
|
59
|
+
isAuthenticated: boolean;
|
|
60
|
+
/** Whether auth state is loading */
|
|
61
|
+
isLoading: boolean;
|
|
62
|
+
/** Whether sign-in is in progress */
|
|
63
|
+
isSigningIn: boolean;
|
|
64
|
+
/** Whether sign-up is in progress */
|
|
65
|
+
isSigningUp: boolean;
|
|
66
|
+
/** Current user (null if not authenticated) */
|
|
67
|
+
user: AuthVitalUser | null;
|
|
68
|
+
/** User's tenants */
|
|
69
|
+
tenants: AuthVitalTenant[];
|
|
70
|
+
/** Currently active tenant */
|
|
71
|
+
currentTenant: AuthVitalTenant | null;
|
|
72
|
+
/** Last error message */
|
|
73
|
+
error: string | null;
|
|
74
|
+
login: (email: string, password: string) => Promise<LoginResult>;
|
|
75
|
+
signIn: (email: string, password: string) => Promise<LoginResult>;
|
|
76
|
+
signUp: (data: SignUpData) => Promise<SignUpResult>;
|
|
77
|
+
signOut: () => Promise<void>;
|
|
78
|
+
logout: () => Promise<void>;
|
|
79
|
+
setActiveTenant: (tenantId: string) => void;
|
|
80
|
+
switchTenant: (tenantId: string) => void;
|
|
81
|
+
refreshToken: () => Promise<void>;
|
|
82
|
+
/** Check if user is authenticated */
|
|
83
|
+
checkAuth: () => Promise<boolean>;
|
|
84
|
+
/**
|
|
85
|
+
* Set the authenticated user and tenants.
|
|
86
|
+
* Call this after your server verifies the JWT using getCurrentUser().
|
|
87
|
+
*/
|
|
88
|
+
setAuthState: (user: AuthVitalUser | null, tenants?: AuthVitalTenant[]) => void;
|
|
89
|
+
/**
|
|
90
|
+
* Clear auth state (call on logout)
|
|
91
|
+
*/
|
|
92
|
+
clearAuthState: () => void;
|
|
93
|
+
}
|
|
94
|
+
interface LoginResult {
|
|
95
|
+
user: AuthVitalUser;
|
|
96
|
+
tenants: AuthVitalTenant[];
|
|
97
|
+
redirectToken?: string;
|
|
98
|
+
redirectUrl?: string;
|
|
99
|
+
}
|
|
100
|
+
interface SignUpData {
|
|
101
|
+
email: string;
|
|
102
|
+
password: string;
|
|
103
|
+
givenName?: string;
|
|
104
|
+
familyName?: string;
|
|
105
|
+
phone?: string;
|
|
106
|
+
}
|
|
107
|
+
interface SignUpResult {
|
|
108
|
+
user: AuthVitalUser;
|
|
109
|
+
tenant?: AuthVitalTenant;
|
|
110
|
+
needsEmailVerification?: boolean;
|
|
111
|
+
}
|
|
112
|
+
interface SignInProps {
|
|
113
|
+
/** Callback on successful sign-in */
|
|
114
|
+
onSuccess?: (user: AuthVitalUser, tenants: AuthVitalTenant[]) => void;
|
|
115
|
+
/** Callback on error */
|
|
116
|
+
onError?: (error: Error) => void;
|
|
117
|
+
/** Show social login buttons (Google, GitHub, etc.) */
|
|
118
|
+
showSocialLogins?: boolean;
|
|
119
|
+
/** Show "Create account" link */
|
|
120
|
+
showSignupLink?: boolean;
|
|
121
|
+
/** Show "Forgot password" link */
|
|
122
|
+
showForgotPassword?: boolean;
|
|
123
|
+
/** Custom redirect after sign-in */
|
|
124
|
+
redirectUrl?: string;
|
|
125
|
+
/** Appearance customization */
|
|
126
|
+
appearance?: AppearanceProps;
|
|
127
|
+
}
|
|
128
|
+
interface SignUpProps {
|
|
129
|
+
/** Callback on successful sign-up initiation (email sent) */
|
|
130
|
+
onSuccess?: (data: any) => void;
|
|
131
|
+
/** Callback on error */
|
|
132
|
+
onError?: (error: Error) => void;
|
|
133
|
+
/** Show social login buttons */
|
|
134
|
+
showSocialLogins?: boolean;
|
|
135
|
+
/** Show "Sign in" link */
|
|
136
|
+
showSignInLink?: boolean;
|
|
137
|
+
/** Show terms checkbox */
|
|
138
|
+
showTerms?: boolean;
|
|
139
|
+
/** Terms of service URL */
|
|
140
|
+
termsUrl?: string;
|
|
141
|
+
/** Privacy policy URL */
|
|
142
|
+
privacyUrl?: string;
|
|
143
|
+
/** Custom redirect after sign-up */
|
|
144
|
+
redirectUrl?: string;
|
|
145
|
+
/** Appearance customization */
|
|
146
|
+
appearance?: AppearanceProps;
|
|
147
|
+
}
|
|
148
|
+
interface UserButtonProps {
|
|
149
|
+
/** Show user's name next to avatar */
|
|
150
|
+
showName?: boolean;
|
|
151
|
+
/** URL to redirect after sign-out */
|
|
152
|
+
afterSignOutUrl?: string;
|
|
153
|
+
/** Custom menu items */
|
|
154
|
+
menuItems?: UserMenuItemProps[];
|
|
155
|
+
}
|
|
156
|
+
interface UserMenuItemProps {
|
|
157
|
+
label: string;
|
|
158
|
+
onClick?: () => void;
|
|
159
|
+
href?: string;
|
|
160
|
+
icon?: ReactNode;
|
|
161
|
+
}
|
|
162
|
+
interface ProtectedRouteProps {
|
|
163
|
+
children: ReactNode;
|
|
164
|
+
/** URL to redirect if not authenticated */
|
|
165
|
+
redirectTo?: string;
|
|
166
|
+
/** Show loading spinner while checking auth */
|
|
167
|
+
showLoading?: boolean;
|
|
168
|
+
/** Custom loading component */
|
|
169
|
+
loadingComponent?: ReactNode;
|
|
170
|
+
}
|
|
171
|
+
interface TenantSwitcherProps {
|
|
172
|
+
/** Callback when tenant changes */
|
|
173
|
+
onChange?: (tenant: AuthVitalTenant) => void;
|
|
174
|
+
/** Show "Create tenant" option */
|
|
175
|
+
showCreateTenant?: boolean;
|
|
176
|
+
/** Appearance customization */
|
|
177
|
+
appearance?: AppearanceProps;
|
|
178
|
+
}
|
|
179
|
+
interface AppearanceProps {
|
|
180
|
+
theme?: 'light' | 'dark' | 'auto';
|
|
181
|
+
variables?: AppearanceVariables;
|
|
182
|
+
elements?: AppearanceElements;
|
|
183
|
+
}
|
|
184
|
+
interface AppearanceVariables {
|
|
185
|
+
colorPrimary?: string;
|
|
186
|
+
colorBackground?: string;
|
|
187
|
+
colorText?: string;
|
|
188
|
+
colorTextSecondary?: string;
|
|
189
|
+
colorDanger?: string;
|
|
190
|
+
colorSuccess?: string;
|
|
191
|
+
borderRadius?: string;
|
|
192
|
+
fontFamily?: string;
|
|
193
|
+
fontSize?: string;
|
|
194
|
+
}
|
|
195
|
+
interface AppearanceElements {
|
|
196
|
+
card?: CSSProperties;
|
|
197
|
+
form?: CSSProperties;
|
|
198
|
+
input?: CSSProperties;
|
|
199
|
+
button?: CSSProperties;
|
|
200
|
+
primaryButton?: CSSProperties;
|
|
201
|
+
secondaryButton?: CSSProperties;
|
|
202
|
+
socialButton?: CSSProperties;
|
|
203
|
+
link?: CSSProperties;
|
|
204
|
+
error?: CSSProperties;
|
|
205
|
+
header?: CSSProperties;
|
|
206
|
+
footer?: CSSProperties;
|
|
207
|
+
}
|
|
208
|
+
interface OAuthConfig {
|
|
209
|
+
authVitalHost: string;
|
|
210
|
+
clientId: string;
|
|
211
|
+
redirectUri: string;
|
|
212
|
+
scope?: string;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Token response from OAuth token endpoint.
|
|
216
|
+
* Note: In cookie-based auth, these tokens are set as httpOnly cookies
|
|
217
|
+
* and are NOT accessible to JavaScript. This type is mainly for
|
|
218
|
+
* server-side SDK use or for understanding the response structure.
|
|
219
|
+
*/
|
|
220
|
+
interface TokenResponse {
|
|
221
|
+
access_token: string;
|
|
222
|
+
token_type: string;
|
|
223
|
+
expires_in: number;
|
|
224
|
+
refresh_token?: string;
|
|
225
|
+
id_token?: string;
|
|
226
|
+
scope?: string;
|
|
227
|
+
}
|
|
228
|
+
interface StandaloneAuthOptions {
|
|
229
|
+
authVitalHost: string;
|
|
230
|
+
clientId: string;
|
|
231
|
+
redirectUri: string;
|
|
232
|
+
scope?: string;
|
|
233
|
+
state?: string;
|
|
234
|
+
}
|
|
235
|
+
interface LoginToAuthVitalOptions {
|
|
236
|
+
screen?: 'login' | 'signup';
|
|
237
|
+
clientId?: string;
|
|
238
|
+
}
|
|
239
|
+
interface InvitationDetails {
|
|
240
|
+
id: string;
|
|
241
|
+
email: string;
|
|
242
|
+
role: string;
|
|
243
|
+
expiresAt: string;
|
|
244
|
+
tenant: {
|
|
245
|
+
id: string;
|
|
246
|
+
name: string;
|
|
247
|
+
slug: string;
|
|
248
|
+
};
|
|
249
|
+
invitedBy: {
|
|
250
|
+
name: string;
|
|
251
|
+
} | null;
|
|
252
|
+
}
|
|
253
|
+
interface CreateInvitationParams {
|
|
254
|
+
email: string;
|
|
255
|
+
tenantId: string;
|
|
256
|
+
role?: string;
|
|
257
|
+
expiresInDays?: number;
|
|
258
|
+
clientId?: string;
|
|
259
|
+
}
|
|
260
|
+
interface CreateInvitationResult {
|
|
261
|
+
id: string;
|
|
262
|
+
email: string;
|
|
263
|
+
token: string;
|
|
264
|
+
role: string;
|
|
265
|
+
expiresAt: string;
|
|
266
|
+
tenant: {
|
|
267
|
+
id: string;
|
|
268
|
+
name: string;
|
|
269
|
+
slug: string;
|
|
270
|
+
};
|
|
271
|
+
inviteUrl: string;
|
|
272
|
+
}
|
|
273
|
+
interface ConsumeInvitationResult {
|
|
274
|
+
success: boolean;
|
|
275
|
+
membership: {
|
|
276
|
+
id: string;
|
|
277
|
+
tenantId: string;
|
|
278
|
+
tenant: {
|
|
279
|
+
id: string;
|
|
280
|
+
name: string;
|
|
281
|
+
slug: string;
|
|
282
|
+
};
|
|
283
|
+
};
|
|
284
|
+
alreadyMember: boolean;
|
|
285
|
+
}
|
|
286
|
+
interface UseInvitationOptions {
|
|
287
|
+
autoConsume?: boolean;
|
|
288
|
+
onConsumed?: (result: ConsumeInvitationResult) => void;
|
|
289
|
+
onError?: (error: Error) => void;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
declare function AuthVitalProvider({ clientId, authVitalHost, initialUser, initialTenants, children, }: AuthVitalProviderProps): react_jsx_runtime.JSX.Element;
|
|
293
|
+
declare function useAuth(): AuthContextValue;
|
|
294
|
+
declare function useUser(): AuthVitalUser | null;
|
|
295
|
+
declare function useTenant(): AuthVitalTenant | null;
|
|
296
|
+
declare function useTenants(): AuthVitalTenant[];
|
|
297
|
+
declare function useAuthVitalConfig(): {
|
|
298
|
+
authVitalHost: string;
|
|
299
|
+
clientId: string;
|
|
300
|
+
};
|
|
301
|
+
declare function useOAuth(options?: {
|
|
302
|
+
redirectUri?: string;
|
|
303
|
+
}): {
|
|
304
|
+
isAuthenticated: boolean;
|
|
305
|
+
isLoading: boolean;
|
|
306
|
+
startLogin: (opts?: {
|
|
307
|
+
state?: string;
|
|
308
|
+
scope?: string;
|
|
309
|
+
}) => Promise<void>;
|
|
310
|
+
startSignup: (opts?: {
|
|
311
|
+
state?: string;
|
|
312
|
+
scope?: string;
|
|
313
|
+
}) => Promise<void>;
|
|
314
|
+
logout: (logoutOptions?: {
|
|
315
|
+
postLogoutRedirectUri?: string;
|
|
316
|
+
}) => Promise<void>;
|
|
317
|
+
};
|
|
318
|
+
declare function useInvitation(options?: UseInvitationOptions): {
|
|
319
|
+
invitation: InvitationDetails | null;
|
|
320
|
+
isLoading: boolean;
|
|
321
|
+
error: Error | null;
|
|
322
|
+
consumed: boolean;
|
|
323
|
+
hasPendingInvite: boolean;
|
|
324
|
+
fetchInvitation: (token: string) => Promise<InvitationDetails>;
|
|
325
|
+
acceptAndLogin: (token: string, loginOptions?: {
|
|
326
|
+
state?: string;
|
|
327
|
+
}) => Promise<void>;
|
|
328
|
+
consumeInvite: (token: string) => Promise<ConsumeInvitationResult>;
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* @authvital/sdk - Browser OAuth Utilities
|
|
333
|
+
*
|
|
334
|
+
* Handles PKCE, authorization flow, and token exchange for browser-based apps.
|
|
335
|
+
*
|
|
336
|
+
* IMPORTANT: Auth state is managed via httpOnly cookies, NOT localStorage.
|
|
337
|
+
* This protects against XSS attacks - JavaScript cannot access the tokens.
|
|
338
|
+
*
|
|
339
|
+
* The PKCE code_verifier is encoded in the OAuth `state` parameter to enable
|
|
340
|
+
* cross-domain flows without storing secrets in the browser.
|
|
341
|
+
*
|
|
342
|
+
* State format: `{csrf_nonce}:{base64url_verifier}`
|
|
343
|
+
*/
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Encode PKCE verifier into OAuth state parameter
|
|
347
|
+
*/
|
|
348
|
+
declare function encodeState(csrf: string, codeVerifier: string): string;
|
|
349
|
+
/**
|
|
350
|
+
* Decode state parameter to extract CSRF and verifier
|
|
351
|
+
*/
|
|
352
|
+
declare function decodeState(state: string): {
|
|
353
|
+
csrf: string;
|
|
354
|
+
codeVerifier: string;
|
|
355
|
+
} | null;
|
|
356
|
+
/**
|
|
357
|
+
* Simple redirect to AuthVital login/signup page.
|
|
358
|
+
* Use this on landing pages where you just want to send users to login.
|
|
359
|
+
*
|
|
360
|
+
* @example
|
|
361
|
+
* ```tsx
|
|
362
|
+
* import { loginToAuthVital } from '@authvital/sdk';
|
|
363
|
+
*
|
|
364
|
+
* <button onClick={() => loginToAuthVital('http://auth.myapp.com', { clientId: 'my-app' })}>
|
|
365
|
+
* Sign In
|
|
366
|
+
* </button>
|
|
367
|
+
* ```
|
|
368
|
+
*/
|
|
369
|
+
declare function loginToAuthVital(authVitalHost: string, options?: LoginToAuthVitalOptions): void;
|
|
370
|
+
/**
|
|
371
|
+
* Convenience function for signup redirect.
|
|
372
|
+
*/
|
|
373
|
+
declare function signupAtAuthVital(authVitalHost: string, options?: Omit<LoginToAuthVitalOptions, 'screen'>): void;
|
|
374
|
+
/**
|
|
375
|
+
* Generate a cryptographically random code verifier
|
|
376
|
+
*/
|
|
377
|
+
declare function generateCodeVerifier(): string;
|
|
378
|
+
/**
|
|
379
|
+
* Generate code challenge from verifier (S256 method)
|
|
380
|
+
*/
|
|
381
|
+
declare function generateCodeChallenge(verifier: string): Promise<string>;
|
|
382
|
+
interface AuthorizeParams {
|
|
383
|
+
state?: string;
|
|
384
|
+
nonce?: string;
|
|
385
|
+
screen?: 'login' | 'signup';
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Start the OAuth authorization flow with PKCE
|
|
389
|
+
*
|
|
390
|
+
* After successful auth, AuthVital sets httpOnly cookies.
|
|
391
|
+
* Use checkAuthStatus() to verify if user is authenticated.
|
|
392
|
+
*/
|
|
393
|
+
declare function startAuthorizationFlow(config: OAuthConfig, params?: AuthorizeParams): Promise<void>;
|
|
394
|
+
/**
|
|
395
|
+
* Start the login flow (standalone function)
|
|
396
|
+
*/
|
|
397
|
+
declare function startLogin(options: StandaloneAuthOptions): Promise<void>;
|
|
398
|
+
/**
|
|
399
|
+
* Start the signup flow (standalone function)
|
|
400
|
+
*/
|
|
401
|
+
declare function startSignup(options: StandaloneAuthOptions): Promise<void>;
|
|
402
|
+
/**
|
|
403
|
+
* Handle the OAuth callback - exchange code for tokens
|
|
404
|
+
*
|
|
405
|
+
* The tokens are set as httpOnly cookies by the server.
|
|
406
|
+
* This function completes the PKCE flow and clears the URL params.
|
|
407
|
+
*/
|
|
408
|
+
declare function handleCallback(config: OAuthConfig): Promise<void>;
|
|
409
|
+
/**
|
|
410
|
+
* Extract callback parameters for trampoline/backend handling
|
|
411
|
+
*/
|
|
412
|
+
declare function extractCallbackParams(): {
|
|
413
|
+
code: string | null;
|
|
414
|
+
codeVerifier: string | null;
|
|
415
|
+
csrf: string | null;
|
|
416
|
+
error: string | null;
|
|
417
|
+
errorDescription: string | null;
|
|
418
|
+
};
|
|
419
|
+
/**
|
|
420
|
+
* Exchange authorization code for tokens.
|
|
421
|
+
* The server sets httpOnly cookies - tokens are NOT returned to JS.
|
|
422
|
+
*/
|
|
423
|
+
declare function exchangeCodeForTokens(config: OAuthConfig, code: string, codeVerifier: string): Promise<TokenResponse>;
|
|
424
|
+
interface AuthStatus {
|
|
425
|
+
authenticated: boolean;
|
|
426
|
+
user?: {
|
|
427
|
+
id: string;
|
|
428
|
+
email: string;
|
|
429
|
+
givenName?: string;
|
|
430
|
+
familyName?: string;
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Check if user is authenticated by calling the auth status endpoint.
|
|
435
|
+
* Auth state is in httpOnly cookies, so we must ask the server.
|
|
436
|
+
*/
|
|
437
|
+
declare function checkAuthStatus(authVitalHost: string): Promise<AuthStatus>;
|
|
438
|
+
/**
|
|
439
|
+
* Logout - clears the httpOnly session cookie via server redirect
|
|
440
|
+
*/
|
|
441
|
+
declare function logout(authVitalHost: string, options?: {
|
|
442
|
+
postLogoutRedirectUri?: string;
|
|
443
|
+
}): Promise<void>;
|
|
444
|
+
/**
|
|
445
|
+
* Decode JWT payload (without verification - for display purposes only)
|
|
446
|
+
*
|
|
447
|
+
* WARNING: Do NOT use this to make auth decisions!
|
|
448
|
+
* Auth state should be verified via checkAuthStatus() which checks cookies.
|
|
449
|
+
*/
|
|
450
|
+
declare function decodeJwt<T = Record<string, unknown>>(token: string): T | null;
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* @authvital/sdk - Client-Side Invitation Helpers
|
|
454
|
+
*
|
|
455
|
+
* Handles the invite flow: get invite details, store token, consume after login.
|
|
456
|
+
* Auth is via httpOnly cookies - no Authorization header needed for authenticated requests.
|
|
457
|
+
*/
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Store invite token in sessionStorage (temporary, for the signup flow)
|
|
461
|
+
*/
|
|
462
|
+
declare function storeInviteToken(token: string): void;
|
|
463
|
+
/**
|
|
464
|
+
* Get stored invite token
|
|
465
|
+
*/
|
|
466
|
+
declare function getStoredInviteToken(): string | null;
|
|
467
|
+
/**
|
|
468
|
+
* Clear stored invite token
|
|
469
|
+
*/
|
|
470
|
+
declare function clearStoredInviteToken(): void;
|
|
471
|
+
/**
|
|
472
|
+
* Check URL for invite token and store it
|
|
473
|
+
*/
|
|
474
|
+
declare function captureInviteTokenFromUrl(): string | null;
|
|
475
|
+
/**
|
|
476
|
+
* Get invitation details by token (public endpoint - no auth required)
|
|
477
|
+
*/
|
|
478
|
+
declare function getInvitation(authVitalHost: string, token: string): Promise<InvitationDetails>;
|
|
479
|
+
/**
|
|
480
|
+
* Create an invitation (requires authentication via cookie)
|
|
481
|
+
*/
|
|
482
|
+
declare function createInvitation(authVitalHost: string, _accessToken: string, // Ignored - auth is via cookie
|
|
483
|
+
params: CreateInvitationParams): Promise<CreateInvitationResult>;
|
|
484
|
+
/**
|
|
485
|
+
* Consume an invitation - adds current user to the tenant
|
|
486
|
+
*/
|
|
487
|
+
declare function consumeInvitation(authVitalHost: string, _accessToken: string, // Ignored - auth is via cookie
|
|
488
|
+
token: string): Promise<ConsumeInvitationResult>;
|
|
489
|
+
/**
|
|
490
|
+
* List pending invitations for a tenant
|
|
491
|
+
*/
|
|
492
|
+
declare function listTenantInvitations(authVitalHost: string, _accessToken: string, // Ignored - auth is via cookie
|
|
493
|
+
tenantId: string): Promise<Array<{
|
|
494
|
+
id: string;
|
|
495
|
+
email: string;
|
|
496
|
+
role: string;
|
|
497
|
+
expiresAt: string;
|
|
498
|
+
createdAt: string;
|
|
499
|
+
invitedBy: {
|
|
500
|
+
id: string;
|
|
501
|
+
email: string;
|
|
502
|
+
givenName: string;
|
|
503
|
+
familyName: string;
|
|
504
|
+
} | null;
|
|
505
|
+
}>>;
|
|
506
|
+
/**
|
|
507
|
+
* Revoke an invitation
|
|
508
|
+
*/
|
|
509
|
+
declare function revokeInvitation(authVitalHost: string, _accessToken: string, // Ignored - auth is via cookie
|
|
510
|
+
invitationId: string): Promise<{
|
|
511
|
+
success: boolean;
|
|
512
|
+
}>;
|
|
513
|
+
|
|
514
|
+
declare function ProtectedRoute({ children, redirectTo, showLoading, loadingComponent, }: ProtectedRouteProps): react_jsx_runtime.JSX.Element | null;
|
|
515
|
+
|
|
516
|
+
interface SignUpFormProps {
|
|
517
|
+
/** Callback when verification email is sent */
|
|
518
|
+
onSuccess?: (data: {
|
|
519
|
+
email: string;
|
|
520
|
+
message: string;
|
|
521
|
+
}) => void;
|
|
522
|
+
/** Callback on error */
|
|
523
|
+
onError?: (error: Error) => void;
|
|
524
|
+
/** Show "Sign in" link */
|
|
525
|
+
showSignInLink?: boolean;
|
|
526
|
+
/** Callback when user clicks sign in link */
|
|
527
|
+
onSignInClick?: () => void;
|
|
528
|
+
/** Redirect URI after signup completion */
|
|
529
|
+
redirectUri?: string;
|
|
530
|
+
/** Appearance customization */
|
|
531
|
+
appearance?: AppearanceProps;
|
|
532
|
+
}
|
|
533
|
+
declare function SignUpForm({ onSuccess, onError, showSignInLink, onSignInClick, redirectUri, appearance, }: SignUpFormProps): react_jsx_runtime.JSX.Element;
|
|
534
|
+
|
|
535
|
+
type VerifyStatus = 'loading' | 'success' | 'error' | 'expired' | 'already_completed';
|
|
536
|
+
interface VerifyEmailProps {
|
|
537
|
+
/** Verification token from URL */
|
|
538
|
+
token: string;
|
|
539
|
+
/** Callback on successful verification */
|
|
540
|
+
onSuccess?: (data: VerifiedData) => void;
|
|
541
|
+
/** Callback on error */
|
|
542
|
+
onError?: (error: Error, status: VerifyStatus) => void;
|
|
543
|
+
/** Callback to continue to complete signup */
|
|
544
|
+
onContinueSignup?: (data: VerifiedData) => void;
|
|
545
|
+
/** Callback to go to login */
|
|
546
|
+
onLogin?: () => void;
|
|
547
|
+
/** Callback to start over (signup again) */
|
|
548
|
+
onStartOver?: () => void;
|
|
549
|
+
/** Appearance customization */
|
|
550
|
+
appearance?: AppearanceProps;
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* Data returned after successful email verification.
|
|
554
|
+
*
|
|
555
|
+
* IMPORTANT: When redirecting to complete-signup, only pass the `token` in the URL.
|
|
556
|
+
* All other data (email, name) should be loaded from the token on the backend to
|
|
557
|
+
* prevent PII from being exposed in URLs.
|
|
558
|
+
*/
|
|
559
|
+
interface VerifiedData {
|
|
560
|
+
/** The verification token - use this (and ONLY this) in redirect URLs */
|
|
561
|
+
token: string;
|
|
562
|
+
/** Email (for display only - do NOT include in URLs) */
|
|
563
|
+
email?: string;
|
|
564
|
+
/** Given name (for display only - do NOT include in URLs) */
|
|
565
|
+
givenName?: string;
|
|
566
|
+
/** Family name (for display only - do NOT include in URLs) */
|
|
567
|
+
familyName?: string;
|
|
568
|
+
/** Tenant name (for display only - do NOT include in URLs) */
|
|
569
|
+
tenantName?: string;
|
|
570
|
+
}
|
|
571
|
+
declare function VerifyEmail({ token, onSuccess, onError, onContinueSignup, onLogin, onStartOver, appearance, }: VerifyEmailProps): react_jsx_runtime.JSX.Element;
|
|
572
|
+
|
|
573
|
+
interface CompleteSignupFormProps {
|
|
574
|
+
/** Verification token */
|
|
575
|
+
token: string;
|
|
576
|
+
/** Email from verification */
|
|
577
|
+
email: string;
|
|
578
|
+
/** Pre-filled given name */
|
|
579
|
+
givenName?: string;
|
|
580
|
+
/** Pre-filled family name */
|
|
581
|
+
familyName?: string;
|
|
582
|
+
/** Pre-filled tenant name */
|
|
583
|
+
tenantName?: string;
|
|
584
|
+
/** Redirect URI after completion */
|
|
585
|
+
redirectUri?: string;
|
|
586
|
+
/** Callback on successful signup */
|
|
587
|
+
onSuccess?: (result: CompleteSignupResult) => void;
|
|
588
|
+
/** Callback on error */
|
|
589
|
+
onError?: (error: Error) => void;
|
|
590
|
+
/** Appearance customization */
|
|
591
|
+
appearance?: AppearanceProps;
|
|
592
|
+
}
|
|
593
|
+
interface CompleteSignupResult {
|
|
594
|
+
user: {
|
|
595
|
+
id: string;
|
|
596
|
+
email: string;
|
|
597
|
+
givenName?: string;
|
|
598
|
+
familyName?: string;
|
|
599
|
+
};
|
|
600
|
+
tenant?: {
|
|
601
|
+
id: string;
|
|
602
|
+
name: string;
|
|
603
|
+
slug: string;
|
|
604
|
+
};
|
|
605
|
+
initiateLoginUri?: string;
|
|
606
|
+
}
|
|
607
|
+
declare function CompleteSignupForm({ token, email, givenName: initialGivenName, familyName: initialFamilyName, tenantName: initialOrgName, redirectUri, onSuccess, onError, appearance, }: CompleteSignupFormProps): react_jsx_runtime.JSX.Element;
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* Shared styles for components
|
|
611
|
+
*/
|
|
612
|
+
|
|
613
|
+
declare function getStyles(appearance?: AppearanceProps): Record<string, CSSProperties>;
|
|
614
|
+
|
|
615
|
+
export { type AppearanceElements, type AppearanceProps, type AppearanceVariables, type AuthContextValue, type AuthStatus, type AuthVitalMembership, AuthVitalProvider, type AuthVitalProviderProps, type AuthVitalTenant, type AuthVitalUser, CompleteSignupForm, type CompleteSignupFormProps, type CompleteSignupResult, type ConsumeInvitationResult, type CreateInvitationParams, type CreateInvitationResult, type InvitationDetails, type LoginResult, type LoginToAuthVitalOptions, type OAuthConfig, ProtectedRoute, type ProtectedRouteProps, type SignInProps, type SignUpData, SignUpForm, type SignUpFormProps, type SignUpProps, type SignUpResult, type StandaloneAuthOptions, type TenantSwitcherProps, type TokenResponse, type UseInvitationOptions, type UserButtonProps, type UserMenuItemProps, type VerifiedData, VerifyEmail, type VerifyEmailProps, captureInviteTokenFromUrl, checkAuthStatus, clearStoredInviteToken, consumeInvitation, createInvitation, decodeJwt, decodeState, encodeState, exchangeCodeForTokens, extractCallbackParams, generateCodeChallenge, generateCodeVerifier, getInvitation, getStoredInviteToken, getStyles, handleCallback, listTenantInvitations, loginToAuthVital, logout, revokeInvitation, signupAtAuthVital, startAuthorizationFlow, startLogin, startSignup, storeInviteToken, useAuth, useAuthVitalConfig, useInvitation, useOAuth, useTenant, useTenants, useUser };
|