mailsentry-auth 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/README.md +36 -0
- package/ZUSTAND_MIGRATION.md +348 -0
- package/dist/index.d.mts +1492 -0
- package/dist/index.d.ts +1492 -0
- package/dist/index.js +2996 -0
- package/dist/index.mjs +2996 -0
- package/dist/middleware.mjs +803 -0
- package/dist/utils/cookie-utils.js +225 -0
- package/dist/utils/cookie-utils.mjs +225 -0
- package/package.json +103 -0
- package/src/app/actions/auth-actions.ts +22 -0
- package/src/app/actions/index.ts +3 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,1492 @@
|
|
|
1
|
+
import { FormInstance } from 'antd/es/form';
|
|
2
|
+
import { Store } from 'rc-field-form/lib/interface';
|
|
3
|
+
import { FormItemProps } from 'antd';
|
|
4
|
+
import * as React$1 from 'react';
|
|
5
|
+
import React__default, { ReactNode } from 'react';
|
|
6
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
7
|
+
import { InputProps } from 'antd/es/input';
|
|
8
|
+
import { PasswordProps } from 'antd/es/input/Password';
|
|
9
|
+
import * as immer from 'immer';
|
|
10
|
+
import * as zustand from 'zustand';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Authentication Stepper Enums
|
|
14
|
+
*
|
|
15
|
+
* This file contains all enum definitions related to authentication flow steps
|
|
16
|
+
* and stepper functionality. These enums provide type safety and better
|
|
17
|
+
* maintainability compared to string literals.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Enum for authentication flow steps in the stepper UI component
|
|
21
|
+
*/
|
|
22
|
+
declare enum AuthFlowStep {
|
|
23
|
+
EMAIL = "email",
|
|
24
|
+
PASSWORD = "password",
|
|
25
|
+
VERIFICATION = "verification"
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Enum for next action after email check
|
|
29
|
+
*/
|
|
30
|
+
declare enum NextAction {
|
|
31
|
+
LOGIN = "login",
|
|
32
|
+
SIGNUP = "signup",
|
|
33
|
+
LOGIN_VERIFICATION = "login-verification"
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface BaseResponse {
|
|
37
|
+
statusCode: number;
|
|
38
|
+
message: string;
|
|
39
|
+
_metadata: {
|
|
40
|
+
languages: string[];
|
|
41
|
+
timestamp: number;
|
|
42
|
+
timezone: string;
|
|
43
|
+
requestId: string;
|
|
44
|
+
path: string;
|
|
45
|
+
version: string;
|
|
46
|
+
repoVersion: string;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
interface EmailExistResponse {
|
|
50
|
+
next_action: NextAction;
|
|
51
|
+
}
|
|
52
|
+
interface LoginRequest {
|
|
53
|
+
email: string;
|
|
54
|
+
password: string;
|
|
55
|
+
}
|
|
56
|
+
interface LoginData {
|
|
57
|
+
roleType: string;
|
|
58
|
+
accessToken: string;
|
|
59
|
+
refreshToken: string;
|
|
60
|
+
isVerifiedEmail: boolean;
|
|
61
|
+
profile: UserProfile;
|
|
62
|
+
tokenInfo: {
|
|
63
|
+
domain: string;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
interface LoginResponse extends BaseResponse {
|
|
67
|
+
data: LoginData;
|
|
68
|
+
}
|
|
69
|
+
interface VerifyEmailRequest {
|
|
70
|
+
email: string;
|
|
71
|
+
code: string;
|
|
72
|
+
}
|
|
73
|
+
interface VerifyEmailResponse extends BaseResponse {
|
|
74
|
+
data: {
|
|
75
|
+
isVerified: boolean;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
interface UserProfile {
|
|
79
|
+
user: {
|
|
80
|
+
_id: string;
|
|
81
|
+
firstName: string;
|
|
82
|
+
lastName: string;
|
|
83
|
+
email: string;
|
|
84
|
+
role: {
|
|
85
|
+
_id: string;
|
|
86
|
+
name: string;
|
|
87
|
+
isActive: boolean;
|
|
88
|
+
type: string;
|
|
89
|
+
permissions: string[];
|
|
90
|
+
createdAt: string;
|
|
91
|
+
updatedAt: string;
|
|
92
|
+
};
|
|
93
|
+
password: string;
|
|
94
|
+
passwordExpired: string;
|
|
95
|
+
passwordCreated: string;
|
|
96
|
+
passwordAttempt: number;
|
|
97
|
+
signUpDate: string;
|
|
98
|
+
signUpFrom: string;
|
|
99
|
+
salt: string;
|
|
100
|
+
isActive: boolean;
|
|
101
|
+
isEmailVerified: boolean;
|
|
102
|
+
inactivePermanent: boolean;
|
|
103
|
+
blocked: boolean;
|
|
104
|
+
createdAt: string;
|
|
105
|
+
updatedAt: string;
|
|
106
|
+
whiteListProject: string;
|
|
107
|
+
};
|
|
108
|
+
credits: Array<{
|
|
109
|
+
_id: string;
|
|
110
|
+
userId: string;
|
|
111
|
+
planId: string;
|
|
112
|
+
amount: number;
|
|
113
|
+
type: string;
|
|
114
|
+
inUse: boolean;
|
|
115
|
+
isDeleted: boolean;
|
|
116
|
+
sharedWith: string | null;
|
|
117
|
+
isExpired: boolean;
|
|
118
|
+
createdAt: string;
|
|
119
|
+
updatedAt: string;
|
|
120
|
+
}>;
|
|
121
|
+
teams: Array<{
|
|
122
|
+
_id: string;
|
|
123
|
+
userId: string;
|
|
124
|
+
teamId: string;
|
|
125
|
+
creditIsInUse: boolean;
|
|
126
|
+
createdAt: string;
|
|
127
|
+
updatedAt: string;
|
|
128
|
+
}>;
|
|
129
|
+
project: {
|
|
130
|
+
_id: string;
|
|
131
|
+
name: string;
|
|
132
|
+
origin: string;
|
|
133
|
+
secretKey: string;
|
|
134
|
+
__v: number;
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
interface UserProfileResponse extends BaseResponse {
|
|
138
|
+
data: UserProfile;
|
|
139
|
+
}
|
|
140
|
+
interface IAuthService {
|
|
141
|
+
checkEmailExists(email: string): Promise<EmailExistResponse>;
|
|
142
|
+
login(credentials: LoginRequest): Promise<LoginResponse>;
|
|
143
|
+
verifyEmail(verification: VerifyEmailRequest): Promise<VerifyEmailResponse>;
|
|
144
|
+
getUserProfile(): Promise<UserProfileResponse>;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
interface AuthActionState {
|
|
148
|
+
isLoading: boolean;
|
|
149
|
+
error: string | null;
|
|
150
|
+
success: string | null;
|
|
151
|
+
}
|
|
152
|
+
interface AuthActionCallbacks<T = unknown> {
|
|
153
|
+
onSuccess?: (data: T, message?: string, result?: AuthActionResult<T>) => void;
|
|
154
|
+
onError?: (error: string) => void;
|
|
155
|
+
}
|
|
156
|
+
interface AuthActionOptions<T = unknown> extends AuthActionCallbacks<T> {
|
|
157
|
+
clearStatesBeforeAction?: boolean;
|
|
158
|
+
preserveSuccessOnError?: boolean;
|
|
159
|
+
}
|
|
160
|
+
interface BaseAuthActionResult {
|
|
161
|
+
message: string;
|
|
162
|
+
nextAction?: NextAction;
|
|
163
|
+
}
|
|
164
|
+
interface AuthActionResultSuccess<T = unknown> extends BaseAuthActionResult {
|
|
165
|
+
success: true;
|
|
166
|
+
data: T;
|
|
167
|
+
}
|
|
168
|
+
interface AuthActionResultFailure extends BaseAuthActionResult {
|
|
169
|
+
success: false;
|
|
170
|
+
error: string;
|
|
171
|
+
}
|
|
172
|
+
type AuthActionResult<T = unknown> = AuthActionResultSuccess<T> | AuthActionResultFailure;
|
|
173
|
+
interface UseAuthActionHandler {
|
|
174
|
+
state: AuthActionState;
|
|
175
|
+
executeAction: <T = unknown>(action: () => Promise<AuthActionResult<T>>, options?: AuthActionOptions<T>) => Promise<AuthActionResult<T> | null>;
|
|
176
|
+
clearError: () => void;
|
|
177
|
+
clearSuccess: () => void;
|
|
178
|
+
clearAll: () => void;
|
|
179
|
+
setSuccess: (message: string) => void;
|
|
180
|
+
setError: (error: string) => void;
|
|
181
|
+
}
|
|
182
|
+
interface UseAuthEventBusProps {
|
|
183
|
+
onLoggedOut?: () => void;
|
|
184
|
+
onLoggedIn?: () => void;
|
|
185
|
+
}
|
|
186
|
+
interface UseFormSubmissionProps<T> {
|
|
187
|
+
onSubmit: (values: T) => void | Promise<void>;
|
|
188
|
+
onError?: (error: unknown) => void;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Authentication Orchestrator Interface
|
|
193
|
+
* Follows Interface Segregation Principle (ISP)
|
|
194
|
+
*/
|
|
195
|
+
interface IAuthOrchestrator {
|
|
196
|
+
handleEmailCheck(email: string): Promise<AuthActionResult>;
|
|
197
|
+
handleLoginFlow(credentials: LoginRequest): Promise<AuthActionResult>;
|
|
198
|
+
handleEmailVerification(email: string, code: string): Promise<AuthActionResult>;
|
|
199
|
+
handleLogout(): Promise<AuthActionResult>;
|
|
200
|
+
checkAuthenticationStatus(): Promise<AuthActionResult>;
|
|
201
|
+
getUserProfileData(): Promise<AuthActionResult>;
|
|
202
|
+
getTokenInfo(): Promise<AuthActionResult>;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
declare enum HttpMethod {
|
|
206
|
+
GET = "GET",
|
|
207
|
+
POST = "POST",
|
|
208
|
+
PUT = "PUT",
|
|
209
|
+
DELETE = "DELETE",
|
|
210
|
+
PATCH = "PATCH"
|
|
211
|
+
}
|
|
212
|
+
interface ApiKeyConfig {
|
|
213
|
+
apiKey: string;
|
|
214
|
+
headerName?: string;
|
|
215
|
+
}
|
|
216
|
+
interface HttpClientConfig {
|
|
217
|
+
baseURL: string;
|
|
218
|
+
timeout?: number;
|
|
219
|
+
retries?: number;
|
|
220
|
+
apiKey?: ApiKeyConfig;
|
|
221
|
+
apiKeys?: Record<string, string>;
|
|
222
|
+
origin?: string;
|
|
223
|
+
headers?: Record<string, string>;
|
|
224
|
+
getAccessToken?: () => Promise<string | null>;
|
|
225
|
+
}
|
|
226
|
+
interface HttpRequestOptions {
|
|
227
|
+
method: HttpMethod;
|
|
228
|
+
url: string;
|
|
229
|
+
data?: unknown;
|
|
230
|
+
body?: unknown;
|
|
231
|
+
headers?: Record<string, string>;
|
|
232
|
+
timeout?: number;
|
|
233
|
+
}
|
|
234
|
+
interface HttpResponse<T = unknown> {
|
|
235
|
+
data: T;
|
|
236
|
+
status: number;
|
|
237
|
+
statusText: string;
|
|
238
|
+
headers: Headers;
|
|
239
|
+
ok: boolean;
|
|
240
|
+
}
|
|
241
|
+
interface ApiErrorResponse {
|
|
242
|
+
message: string;
|
|
243
|
+
statusCode: number;
|
|
244
|
+
error: string;
|
|
245
|
+
digest?: string;
|
|
246
|
+
}
|
|
247
|
+
interface HttpError extends Error {
|
|
248
|
+
status?: number;
|
|
249
|
+
statusText?: string;
|
|
250
|
+
response?: unknown;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
interface AlertDisplayProps {
|
|
254
|
+
error?: string;
|
|
255
|
+
success?: string;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
interface FormHeaderProps {
|
|
259
|
+
title: string;
|
|
260
|
+
description?: string;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
interface BaseFormField extends Omit<FormItemProps, 'children'> {
|
|
264
|
+
component: React.ReactNode;
|
|
265
|
+
}
|
|
266
|
+
interface FormFieldsProps {
|
|
267
|
+
fields: BaseFormField[];
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
interface BaseComponentProps extends FormHeaderProps, AlertDisplayProps {
|
|
271
|
+
submitButtonText: string;
|
|
272
|
+
isLoading?: boolean;
|
|
273
|
+
initialValues?: Store;
|
|
274
|
+
}
|
|
275
|
+
type BaseStepProps = BaseComponentProps;
|
|
276
|
+
interface BaseFormProps<T = Record<string, unknown>> extends BaseComponentProps, FormFieldsProps {
|
|
277
|
+
onSubmit: (values: T) => void | Promise<void>;
|
|
278
|
+
form?: FormInstance;
|
|
279
|
+
additionalActions?: React.ReactNode;
|
|
280
|
+
showAlerts?: boolean;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
interface EmailStepProps extends BaseStepProps {
|
|
284
|
+
onSubmit: (email: string) => void | Promise<void>;
|
|
285
|
+
onGoogleSignIn?: () => void;
|
|
286
|
+
onForgotPassword?: () => void;
|
|
287
|
+
showGoogleButton?: boolean;
|
|
288
|
+
showForgotPassword?: boolean;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
interface PasswordStepProps extends BaseStepProps {
|
|
292
|
+
mode: NextAction;
|
|
293
|
+
email: string;
|
|
294
|
+
onSubmit: (password: string) => void | Promise<void>;
|
|
295
|
+
onBack?: () => void;
|
|
296
|
+
showEmailField?: boolean;
|
|
297
|
+
showBackButton?: boolean;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
interface VerificationStepProps extends BaseStepProps {
|
|
301
|
+
email: string;
|
|
302
|
+
onSubmit: (verificationCode: string) => void | Promise<void>;
|
|
303
|
+
onBack?: () => void;
|
|
304
|
+
onResendCode?: () => void;
|
|
305
|
+
codeLength?: number;
|
|
306
|
+
showBackButton?: boolean;
|
|
307
|
+
showResendButton?: boolean;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
declare enum ProfileUIState {
|
|
311
|
+
LOADING = "LOADING",
|
|
312
|
+
UNAUTHENTICATED = "UNAUTHENTICATED",
|
|
313
|
+
AUTHENTICATED = "AUTHENTICATED"
|
|
314
|
+
}
|
|
315
|
+
interface AuthenticatedStateProps {
|
|
316
|
+
user: UserProfile;
|
|
317
|
+
onLogout: () => void;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
interface Step<T = string> {
|
|
321
|
+
id: T;
|
|
322
|
+
title: string;
|
|
323
|
+
description: string;
|
|
324
|
+
icon?: ReactNode;
|
|
325
|
+
disabled?: boolean;
|
|
326
|
+
}
|
|
327
|
+
interface StepConfig<T = string> {
|
|
328
|
+
steps: Step<T>[];
|
|
329
|
+
initialStep?: T;
|
|
330
|
+
}
|
|
331
|
+
interface StepperState$1<T = string> {
|
|
332
|
+
currentStep: T;
|
|
333
|
+
currentStepIndex: number;
|
|
334
|
+
steps: Step<T>[];
|
|
335
|
+
isFirstStep: boolean;
|
|
336
|
+
isLastStep: boolean;
|
|
337
|
+
progress: number;
|
|
338
|
+
}
|
|
339
|
+
interface StepperActions<T = string> {
|
|
340
|
+
goToStep: (step: T) => void;
|
|
341
|
+
goToNext: () => void;
|
|
342
|
+
goToPrevious: () => void;
|
|
343
|
+
goToIndex: (index: number) => void;
|
|
344
|
+
reset: () => void;
|
|
345
|
+
}
|
|
346
|
+
interface UseStepperReturn<T = string> {
|
|
347
|
+
state: StepperState$1<T>;
|
|
348
|
+
actions: StepperActions<T>;
|
|
349
|
+
helpers: {
|
|
350
|
+
getStepIndex: (step: T) => number;
|
|
351
|
+
getStepByIndex: (index: number) => Step<T> | undefined;
|
|
352
|
+
isStepValid: (step: T) => boolean;
|
|
353
|
+
getProgressPercentage: () => number;
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
type StepRegistryBaseProps = Omit<BaseStepProps, 'title' | 'description' | 'submitButtonText'>;
|
|
358
|
+
interface StepRegistryParams {
|
|
359
|
+
baseProps: StepRegistryBaseProps;
|
|
360
|
+
handlers: StepRegistryHandlers;
|
|
361
|
+
state: StepRegistryState;
|
|
362
|
+
configs: StepRegistryConfigs;
|
|
363
|
+
}
|
|
364
|
+
interface UseStepRegistryParams extends StepRegistryParams {
|
|
365
|
+
getStepComponent: (step: AuthFlowStep) => StepComponent | null;
|
|
366
|
+
stepperState: StepperState;
|
|
367
|
+
}
|
|
368
|
+
interface StepRegistryHandlers {
|
|
369
|
+
handleEmailSubmit: (email: string) => Promise<void>;
|
|
370
|
+
handlePasswordSubmit: (password: string) => Promise<void>;
|
|
371
|
+
handleVerificationSubmit: (code: string) => Promise<void>;
|
|
372
|
+
handleResendCode: () => void;
|
|
373
|
+
goBackToEmail: () => void;
|
|
374
|
+
goBackToPassword: () => void;
|
|
375
|
+
onGoogleSignIn?: () => void;
|
|
376
|
+
onForgotPassword?: () => void;
|
|
377
|
+
}
|
|
378
|
+
interface StepRegistryState {
|
|
379
|
+
email: string;
|
|
380
|
+
authIntent: NextAction;
|
|
381
|
+
authData: unknown;
|
|
382
|
+
}
|
|
383
|
+
interface StepRegistryConfigs {
|
|
384
|
+
emailStepConfig: Record<string, unknown>;
|
|
385
|
+
passwordStepConfig: Record<string, unknown>;
|
|
386
|
+
verificationStepConfig: Record<string, unknown>;
|
|
387
|
+
}
|
|
388
|
+
interface StepperState {
|
|
389
|
+
currentStep: AuthFlowStep;
|
|
390
|
+
}
|
|
391
|
+
type StepComponentRetriever = (step: AuthFlowStep) => StepComponent | null;
|
|
392
|
+
type AnyStepProps = EmailStepProps | PasswordStepProps | VerificationStepProps;
|
|
393
|
+
type StepComponent = React__default.ComponentType<AnyStepProps>;
|
|
394
|
+
type StepRegistry = Record<AuthFlowStep, StepComponent>;
|
|
395
|
+
type PropsFactory = () => AnyStepProps;
|
|
396
|
+
type StepPropsFactoryRegistry = Record<AuthFlowStep, PropsFactory>;
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Enum for user roles
|
|
400
|
+
*/
|
|
401
|
+
declare enum RoleType {
|
|
402
|
+
USER = "USER",
|
|
403
|
+
ADMIN = "ADMIN"
|
|
404
|
+
}
|
|
405
|
+
type AuthState = {
|
|
406
|
+
isAuthenticated: boolean;
|
|
407
|
+
isLoading: boolean;
|
|
408
|
+
error: string | null;
|
|
409
|
+
user: Record<string, unknown> | null;
|
|
410
|
+
tokens: {
|
|
411
|
+
accessToken: string | null;
|
|
412
|
+
refreshToken: string | null;
|
|
413
|
+
};
|
|
414
|
+
};
|
|
415
|
+
type EmailCheckResult = {
|
|
416
|
+
exists: boolean;
|
|
417
|
+
nextAction: NextAction;
|
|
418
|
+
message: string;
|
|
419
|
+
};
|
|
420
|
+
type UserSession = {
|
|
421
|
+
user: {
|
|
422
|
+
id: string;
|
|
423
|
+
email: string;
|
|
424
|
+
firstName: string;
|
|
425
|
+
lastName: string;
|
|
426
|
+
role: RoleType;
|
|
427
|
+
};
|
|
428
|
+
tokens: {
|
|
429
|
+
accessToken: string;
|
|
430
|
+
refreshToken: string;
|
|
431
|
+
};
|
|
432
|
+
expiresAt: number;
|
|
433
|
+
};
|
|
434
|
+
type UserState = {
|
|
435
|
+
user: UserProfile | null;
|
|
436
|
+
isLoading: boolean;
|
|
437
|
+
error: string | null;
|
|
438
|
+
isAuthenticated: boolean;
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Token Management Interface
|
|
443
|
+
* Follows Single Responsibility Principle (SRP)
|
|
444
|
+
* Updated to support async operations for SSR compatibility
|
|
445
|
+
*/
|
|
446
|
+
interface ITokenManager {
|
|
447
|
+
saveTokens(accessToken: string, refreshToken?: string): void;
|
|
448
|
+
clearTokens(): void;
|
|
449
|
+
getAccessToken(): Promise<string | null>;
|
|
450
|
+
getRefreshToken(): Promise<string | null>;
|
|
451
|
+
getAllTokens(): Promise<Record<string, string>>;
|
|
452
|
+
areCookiesSupported(): boolean;
|
|
453
|
+
getDomainInfo(): Record<string, string>;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Strategy Pattern: Login Flow Strategy Interface
|
|
458
|
+
*/
|
|
459
|
+
interface ILoginFlowStrategy {
|
|
460
|
+
execute(credentials: LoginRequest): Promise<AuthActionResult<LoginData>>;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* State Pattern: Authentication Status State Interface
|
|
465
|
+
*/
|
|
466
|
+
interface IAuthStatusState {
|
|
467
|
+
getStatus(tokenManager: ITokenManager): Promise<AuthActionResult>;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Chain of Responsibility: Error Handler Interface
|
|
472
|
+
*/
|
|
473
|
+
interface IErrorHandler {
|
|
474
|
+
setNext(handler: IErrorHandler): IErrorHandler;
|
|
475
|
+
handle(error: unknown, context: string): AuthActionResult;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* Lookup Pattern: Logger Interface
|
|
480
|
+
*/
|
|
481
|
+
interface ILogger {
|
|
482
|
+
log(message: string, data?: unknown): void;
|
|
483
|
+
warn(message: string, data?: unknown): void;
|
|
484
|
+
error(message: string, data?: unknown): void;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
interface Subscription {
|
|
488
|
+
unsubscribe(): void;
|
|
489
|
+
}
|
|
490
|
+
interface EventBus<TEvent = unknown> {
|
|
491
|
+
publish(event: TEvent): void;
|
|
492
|
+
subscribe(handler: (event: TEvent) => void): Subscription;
|
|
493
|
+
}
|
|
494
|
+
declare abstract class BaseEventBus {
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
declare enum AuthEventType {
|
|
498
|
+
LoggedIn = "auth.logged_in",
|
|
499
|
+
LoggedOut = "auth.logged_out",
|
|
500
|
+
EmailVerified = "auth.email_verified",
|
|
501
|
+
SignInRequiredModal = "auth.signin_required_modal"
|
|
502
|
+
}
|
|
503
|
+
type AuthEvent = {
|
|
504
|
+
type: AuthEventType.LoggedIn;
|
|
505
|
+
userId: string;
|
|
506
|
+
sourcePageType?: PageType;
|
|
507
|
+
} | {
|
|
508
|
+
type: AuthEventType.LoggedOut;
|
|
509
|
+
sourcePageType?: PageType;
|
|
510
|
+
} | {
|
|
511
|
+
type: AuthEventType.EmailVerified;
|
|
512
|
+
email: string;
|
|
513
|
+
sourcePageType?: PageType;
|
|
514
|
+
} | {
|
|
515
|
+
type: AuthEventType.SignInRequiredModal;
|
|
516
|
+
sourcePageType?: PageType;
|
|
517
|
+
};
|
|
518
|
+
declare enum PageType {
|
|
519
|
+
LOGIN = "/login",
|
|
520
|
+
DASHBOARD = "/dashboard",
|
|
521
|
+
HOME = "/"
|
|
522
|
+
}
|
|
523
|
+
declare enum NavigationAction {
|
|
524
|
+
NONE = "none",
|
|
525
|
+
REDIRECT = "redirect",
|
|
526
|
+
MODAL = "modal"
|
|
527
|
+
}
|
|
528
|
+
declare const PageTypePatterns: {
|
|
529
|
+
readonly "/login": PageType.LOGIN;
|
|
530
|
+
readonly "/dashboard": PageType.DASHBOARD;
|
|
531
|
+
readonly "/": PageType.HOME;
|
|
532
|
+
};
|
|
533
|
+
declare const CrossTabBehaviorConfig: {
|
|
534
|
+
readonly "/login": {
|
|
535
|
+
readonly "auth.logged_in": {
|
|
536
|
+
readonly action: NavigationAction.REDIRECT;
|
|
537
|
+
readonly target: PageType.DASHBOARD;
|
|
538
|
+
};
|
|
539
|
+
readonly "auth.logged_out": {
|
|
540
|
+
readonly action: NavigationAction.NONE;
|
|
541
|
+
};
|
|
542
|
+
readonly "auth.email_verified": {
|
|
543
|
+
readonly action: NavigationAction.NONE;
|
|
544
|
+
};
|
|
545
|
+
readonly "auth.signin_required_modal": {
|
|
546
|
+
readonly action: NavigationAction.NONE;
|
|
547
|
+
};
|
|
548
|
+
};
|
|
549
|
+
readonly "/dashboard": {
|
|
550
|
+
readonly "auth.logged_in": {
|
|
551
|
+
readonly action: NavigationAction.MODAL;
|
|
552
|
+
};
|
|
553
|
+
readonly "auth.logged_out": {
|
|
554
|
+
readonly action: NavigationAction.REDIRECT;
|
|
555
|
+
readonly target: PageType.DASHBOARD;
|
|
556
|
+
};
|
|
557
|
+
readonly "auth.email_verified": {
|
|
558
|
+
readonly action: NavigationAction.MODAL;
|
|
559
|
+
};
|
|
560
|
+
readonly "auth.signin_required_modal": {
|
|
561
|
+
readonly action: NavigationAction.NONE;
|
|
562
|
+
};
|
|
563
|
+
};
|
|
564
|
+
readonly "/": {
|
|
565
|
+
readonly "auth.logged_in": {
|
|
566
|
+
readonly action: NavigationAction.MODAL;
|
|
567
|
+
};
|
|
568
|
+
readonly "auth.logged_out": {
|
|
569
|
+
readonly action: NavigationAction.REDIRECT;
|
|
570
|
+
readonly target: PageType.HOME;
|
|
571
|
+
};
|
|
572
|
+
readonly "auth.email_verified": {
|
|
573
|
+
readonly action: NavigationAction.MODAL;
|
|
574
|
+
};
|
|
575
|
+
readonly "auth.signin_required_modal": {
|
|
576
|
+
readonly action: NavigationAction.NONE;
|
|
577
|
+
};
|
|
578
|
+
};
|
|
579
|
+
};
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* Middleware request context containing all necessary data
|
|
583
|
+
*/
|
|
584
|
+
interface MiddlewareContext {
|
|
585
|
+
request: NextRequest;
|
|
586
|
+
method: string;
|
|
587
|
+
pathname: string;
|
|
588
|
+
searchParams: URLSearchParams;
|
|
589
|
+
cookies: NextRequest['cookies'];
|
|
590
|
+
nextUrl: URL;
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* Base interface for middleware handlers
|
|
594
|
+
*/
|
|
595
|
+
interface MiddlewareHandler {
|
|
596
|
+
handle(context: MiddlewareContext): NextResponse | null | Promise<NextResponse | null>;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
declare enum Channel {
|
|
600
|
+
AUTH = "auth-event-channel"
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
declare const createAuthSteps: (options?: {
|
|
604
|
+
authIntent?: NextAction;
|
|
605
|
+
nextAction?: NextAction;
|
|
606
|
+
}) => Step<AuthFlowStep>[];
|
|
607
|
+
declare const getStepProgressMessage: (step: AuthFlowStep) => string;
|
|
608
|
+
declare const getAuthPageStepMessage: (step: AuthFlowStep) => string;
|
|
609
|
+
|
|
610
|
+
declare const EMAIL_SUBMISSION_NAVIGATION: {
|
|
611
|
+
readonly "login-verification": AuthFlowStep.VERIFICATION;
|
|
612
|
+
readonly login: AuthFlowStep.PASSWORD;
|
|
613
|
+
readonly signup: AuthFlowStep.PASSWORD;
|
|
614
|
+
};
|
|
615
|
+
declare const PASSWORD_SUBMISSION_NAVIGATION: {
|
|
616
|
+
readonly VERIFIED: AuthFlowStep.VERIFICATION;
|
|
617
|
+
readonly UNVERIFIED: AuthFlowStep.VERIFICATION;
|
|
618
|
+
};
|
|
619
|
+
declare const VERIFICATION_SUBMISSION_NAVIGATION: {
|
|
620
|
+
readonly SUCCESS: AuthFlowStep.VERIFICATION;
|
|
621
|
+
readonly ERROR: AuthFlowStep.VERIFICATION;
|
|
622
|
+
};
|
|
623
|
+
declare const getStepForEmailSubmission: (nextAction: NextAction) => AuthFlowStep;
|
|
624
|
+
declare const getStepForPasswordSubmission: (isVerified: boolean) => AuthFlowStep;
|
|
625
|
+
declare const getStepForVerificationSubmission: (success: boolean) => AuthFlowStep;
|
|
626
|
+
|
|
627
|
+
declare const getEmailField: (options?: InputProps) => BaseFormField;
|
|
628
|
+
declare const getPasswordField: (isLogin: boolean, disabled?: boolean, options?: PasswordProps) => BaseFormField;
|
|
629
|
+
declare const getVerificationField: (codeLength?: number, options?: InputProps) => BaseFormField;
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* Middleware configuration constants
|
|
633
|
+
*/
|
|
634
|
+
declare class MiddlewareConfig {
|
|
635
|
+
static readonly PROTECTED_ROUTES: {
|
|
636
|
+
readonly DASHBOARD: "/";
|
|
637
|
+
};
|
|
638
|
+
static readonly AUTH_ROUTES: {
|
|
639
|
+
readonly LOGIN: "/login";
|
|
640
|
+
};
|
|
641
|
+
static readonly ALLOWED_METHODS: readonly ["GET", "HEAD"];
|
|
642
|
+
static readonly QUERY_PARAMS: {
|
|
643
|
+
readonly LOGIN_REQUIRED: "sign_in_required";
|
|
644
|
+
readonly AUTH_CHECKED: "auth_checked";
|
|
645
|
+
};
|
|
646
|
+
static readonly QUERY_VALUES: {
|
|
647
|
+
readonly LOGIN_REQUIRED: "true";
|
|
648
|
+
readonly AUTH_CHECKED: "1";
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* Middleware matcher patterns - exported separately for static analysis
|
|
653
|
+
* Pattern includes:
|
|
654
|
+
* - / (home route and all other routes for authentication protection)
|
|
655
|
+
* - /login route (for authenticated user redirection)
|
|
656
|
+
* Excludes: API routes, Next.js internals, static assets, and file extensions
|
|
657
|
+
*/
|
|
658
|
+
declare const middlewareMatcher: readonly ["/((?!api|_next/static|_next/image|_next/webpack-hmr|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp|ico|css|js)$).*)", "/login"];
|
|
659
|
+
/**
|
|
660
|
+
* Middleware configuration - runs on all routes (including home) and login page
|
|
661
|
+
*/
|
|
662
|
+
declare const config: {
|
|
663
|
+
matcher: readonly ["/((?!api|_next/static|_next/image|_next/webpack-hmr|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp|ico|css|js)$).*)", "/login"];
|
|
664
|
+
};
|
|
665
|
+
|
|
666
|
+
/**
|
|
667
|
+
* Cookie utility for managing authentication tokens with automatic SSR and client-side support
|
|
668
|
+
* Automatically chooses the right method based on environment
|
|
669
|
+
*/
|
|
670
|
+
declare class CookieUtils {
|
|
671
|
+
/**
|
|
672
|
+
* Get the access token cookie key from environment variables
|
|
673
|
+
*/
|
|
674
|
+
static getAccessTokenKey(): string;
|
|
675
|
+
/**
|
|
676
|
+
* Get the refresh token cookie key from environment variables
|
|
677
|
+
*/
|
|
678
|
+
static getRefreshTokenKey(): string;
|
|
679
|
+
private static readonly COOKIE_DOMAIN;
|
|
680
|
+
/**
|
|
681
|
+
* Get root domain for subdomain support
|
|
682
|
+
*/
|
|
683
|
+
private static getRootDomain;
|
|
684
|
+
/**
|
|
685
|
+
* Get common cookie options
|
|
686
|
+
*/
|
|
687
|
+
private static getCookieOptions;
|
|
688
|
+
/**
|
|
689
|
+
* Check if running on client side
|
|
690
|
+
*/
|
|
691
|
+
private static isClientSide;
|
|
692
|
+
/**
|
|
693
|
+
* Check if running on server side
|
|
694
|
+
*/
|
|
695
|
+
private static isServerSide;
|
|
696
|
+
/**
|
|
697
|
+
* Dynamically import server action for server-side operations
|
|
698
|
+
*/
|
|
699
|
+
private static getServerTokens;
|
|
700
|
+
/**
|
|
701
|
+
* Set access token in cookie (client-side only)
|
|
702
|
+
*/
|
|
703
|
+
static setAccessToken(token: string): void;
|
|
704
|
+
/**
|
|
705
|
+
* Set refresh token in cookie (client-side only)
|
|
706
|
+
*/
|
|
707
|
+
static setRefreshToken(token: string): void;
|
|
708
|
+
/**
|
|
709
|
+
* Get access token - automatically handles client/server side
|
|
710
|
+
*/
|
|
711
|
+
static getAccessToken(): Promise<string | null>;
|
|
712
|
+
/**
|
|
713
|
+
* Get refresh token - automatically handles client/server side
|
|
714
|
+
*/
|
|
715
|
+
static getRefreshToken(): Promise<string | null>;
|
|
716
|
+
/**
|
|
717
|
+
* Get both tokens - automatically handles client/server side
|
|
718
|
+
*/
|
|
719
|
+
static getTokens(): Promise<{
|
|
720
|
+
accessToken: string | null;
|
|
721
|
+
refreshToken: string | null;
|
|
722
|
+
}>;
|
|
723
|
+
/**
|
|
724
|
+
* Clear all authentication cookies (client-side only)
|
|
725
|
+
*/
|
|
726
|
+
static clearAuthCookies(): void;
|
|
727
|
+
/**
|
|
728
|
+
* Check if cookies are supported/enabled (client-side only)
|
|
729
|
+
*/
|
|
730
|
+
static areCookiesEnabled(): boolean;
|
|
731
|
+
/**
|
|
732
|
+
* Get all authentication cookies - automatically handles client/server side
|
|
733
|
+
*/
|
|
734
|
+
static getAllAuthCookies(): Promise<Record<string, string>>;
|
|
735
|
+
/**
|
|
736
|
+
* Set multiple tokens at once (client-side only)
|
|
737
|
+
*/
|
|
738
|
+
static setTokens(accessToken: string, refreshToken: string): void;
|
|
739
|
+
/**
|
|
740
|
+
* Check if user has valid tokens - automatically handles client/server side
|
|
741
|
+
*/
|
|
742
|
+
static hasValidTokens(): Promise<boolean>;
|
|
743
|
+
/**
|
|
744
|
+
* Get current domain information for debugging
|
|
745
|
+
*/
|
|
746
|
+
static getDomainInfo(): Record<string, string>;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
/**
|
|
750
|
+
* LocalStorage utility for managing user profile data with automatic caching and expiration
|
|
751
|
+
*/
|
|
752
|
+
declare class LocalStorageUtils {
|
|
753
|
+
private static readonly USER_PROFILE_STORAGE_KEY;
|
|
754
|
+
private static readonly USER_PROFILE_TIMESTAMP_KEY;
|
|
755
|
+
private static readonly DEFAULT_CACHE_DURATION;
|
|
756
|
+
/**
|
|
757
|
+
* Check if localStorage is available
|
|
758
|
+
*/
|
|
759
|
+
private static isAvailable;
|
|
760
|
+
/**
|
|
761
|
+
* Save user profile to localStorage with timestamp
|
|
762
|
+
*/
|
|
763
|
+
static saveUserProfile(userProfile: UserProfile): boolean;
|
|
764
|
+
/**
|
|
765
|
+
* Get user profile from localStorage with cache validation
|
|
766
|
+
*/
|
|
767
|
+
static getUserProfile(cacheDuration?: number): UserProfile | null;
|
|
768
|
+
/**
|
|
769
|
+
* Clear user profile data from localStorage
|
|
770
|
+
*/
|
|
771
|
+
static clearUserProfile(): boolean;
|
|
772
|
+
/**
|
|
773
|
+
* Check if cached user profile is still valid
|
|
774
|
+
*/
|
|
775
|
+
static isCacheValid(cacheDuration?: number): boolean;
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
type Handler<T> = (e: T) => void;
|
|
779
|
+
declare class BroadcastChannelEventBus<TEvent> {
|
|
780
|
+
private channel?;
|
|
781
|
+
private readonly listeners;
|
|
782
|
+
private readonly name;
|
|
783
|
+
private constructor();
|
|
784
|
+
static getInstance<T>(name: Channel): BroadcastChannelEventBus<T>;
|
|
785
|
+
publish(event: TEvent): void;
|
|
786
|
+
subscribe(handler: Handler<TEvent>): {
|
|
787
|
+
unsubscribe: () => boolean;
|
|
788
|
+
};
|
|
789
|
+
private emit;
|
|
790
|
+
close(): void;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
/**
|
|
794
|
+
* Cross-Tab Behavior Handler
|
|
795
|
+
* Determines cross-tab behavior based on authentication events and current page context
|
|
796
|
+
* Uses lookup patterns instead of conditional statements
|
|
797
|
+
*/
|
|
798
|
+
declare class CrossTabBehaviorHandler {
|
|
799
|
+
/**
|
|
800
|
+
* Get current page type based on pathname using pattern matching
|
|
801
|
+
*/
|
|
802
|
+
static getCurrentPageType(): PageType;
|
|
803
|
+
/**
|
|
804
|
+
* Get the action configuration for current route and event
|
|
805
|
+
*/
|
|
806
|
+
static getAction(currentPageType: PageType, eventType: AuthEventType): {
|
|
807
|
+
readonly action: NavigationAction.REDIRECT;
|
|
808
|
+
readonly target: PageType.DASHBOARD;
|
|
809
|
+
} | {
|
|
810
|
+
readonly action: NavigationAction.NONE;
|
|
811
|
+
} | {
|
|
812
|
+
readonly action: NavigationAction.NONE;
|
|
813
|
+
} | {
|
|
814
|
+
readonly action: NavigationAction.NONE;
|
|
815
|
+
} | {
|
|
816
|
+
readonly action: NavigationAction.MODAL;
|
|
817
|
+
} | {
|
|
818
|
+
readonly action: NavigationAction.REDIRECT;
|
|
819
|
+
readonly target: PageType.DASHBOARD;
|
|
820
|
+
} | {
|
|
821
|
+
readonly action: NavigationAction.MODAL;
|
|
822
|
+
} | {
|
|
823
|
+
readonly action: NavigationAction.NONE;
|
|
824
|
+
} | {
|
|
825
|
+
readonly action: NavigationAction.MODAL;
|
|
826
|
+
} | {
|
|
827
|
+
readonly action: NavigationAction.REDIRECT;
|
|
828
|
+
readonly target: PageType.HOME;
|
|
829
|
+
} | {
|
|
830
|
+
readonly action: NavigationAction.MODAL;
|
|
831
|
+
} | {
|
|
832
|
+
readonly action: NavigationAction.NONE;
|
|
833
|
+
};
|
|
834
|
+
/**
|
|
835
|
+
* Check if current route requires redirect for given event
|
|
836
|
+
*/
|
|
837
|
+
static shouldRedirect(currentPageType: PageType, eventType: AuthEventType): PageType | null;
|
|
838
|
+
/**
|
|
839
|
+
* Check if current route should show modal for given event
|
|
840
|
+
*/
|
|
841
|
+
static shouldShowModal(currentPageType: PageType, eventType: AuthEventType): boolean;
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
/**
|
|
845
|
+
* Token Manager Implementation
|
|
846
|
+
* Handles token storage and validation using CookieUtils
|
|
847
|
+
* Updated to support async operations for SSR compatibility
|
|
848
|
+
*/
|
|
849
|
+
declare class TokenManager implements ITokenManager {
|
|
850
|
+
private cookieUtils;
|
|
851
|
+
constructor(cookieUtils: typeof CookieUtils);
|
|
852
|
+
saveTokens(accessToken: string, refreshToken?: string): void;
|
|
853
|
+
clearTokens(): void;
|
|
854
|
+
getAccessToken(): Promise<string | null>;
|
|
855
|
+
getRefreshToken(): Promise<string | null>;
|
|
856
|
+
/**
|
|
857
|
+
* Get all stored tokens for debugging or validation
|
|
858
|
+
*/
|
|
859
|
+
getAllTokens(): Promise<Record<string, string>>;
|
|
860
|
+
/**
|
|
861
|
+
* Check if cookies are supported in the current environment
|
|
862
|
+
*/
|
|
863
|
+
areCookiesSupported(): boolean;
|
|
864
|
+
/**
|
|
865
|
+
* Get domain information for debugging
|
|
866
|
+
*/
|
|
867
|
+
getDomainInfo(): Record<string, string>;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
/**
|
|
871
|
+
* HTTP Client with better error handling
|
|
872
|
+
*/
|
|
873
|
+
declare class HttpClient {
|
|
874
|
+
private config;
|
|
875
|
+
constructor(config: HttpClientConfig);
|
|
876
|
+
/**
|
|
877
|
+
* Execute HTTP request
|
|
878
|
+
*/
|
|
879
|
+
request<T>(endpoint: string, options: HttpRequestOptions): Promise<HttpResponse<T>>;
|
|
880
|
+
/**
|
|
881
|
+
* Build headers with defaults including multiple API keys and Bearer token
|
|
882
|
+
*/
|
|
883
|
+
private buildHeaders;
|
|
884
|
+
/**
|
|
885
|
+
* Execute request with timeout
|
|
886
|
+
*/
|
|
887
|
+
private executeWithTimeout;
|
|
888
|
+
}
|
|
889
|
+
/**
|
|
890
|
+
* Base Service with dependency injection and better separation of concerns
|
|
891
|
+
*/
|
|
892
|
+
declare abstract class BaseService {
|
|
893
|
+
protected httpClient: HttpClient;
|
|
894
|
+
protected tokenManager: TokenManager;
|
|
895
|
+
constructor(httpClient?: HttpClient, tokenManager?: TokenManager);
|
|
896
|
+
/**
|
|
897
|
+
* Create default HTTP client with configuration
|
|
898
|
+
*/
|
|
899
|
+
private createDefaultHttpClient;
|
|
900
|
+
/**
|
|
901
|
+
* Handle HTTP response and throw structured error if needed
|
|
902
|
+
*/
|
|
903
|
+
private handleResponse;
|
|
904
|
+
/**
|
|
905
|
+
* Create API error from HTTP response following Single Responsibility Principle
|
|
906
|
+
*/
|
|
907
|
+
private createApiErrorFromResponse;
|
|
908
|
+
/**
|
|
909
|
+
* Try to parse API error response from response data
|
|
910
|
+
*/
|
|
911
|
+
private tryParseApiErrorResponse;
|
|
912
|
+
/**
|
|
913
|
+
* Check if response data has valid API error structure
|
|
914
|
+
*/
|
|
915
|
+
private isValidApiErrorResponse;
|
|
916
|
+
/**
|
|
917
|
+
* Create generic API error as fallback
|
|
918
|
+
*/
|
|
919
|
+
private createGenericApiError;
|
|
920
|
+
/**
|
|
921
|
+
* GET request
|
|
922
|
+
*/
|
|
923
|
+
protected get<T>(endpoint: string, headers?: Record<string, string>): Promise<T>;
|
|
924
|
+
/**
|
|
925
|
+
* POST request
|
|
926
|
+
*/
|
|
927
|
+
protected post<T>(endpoint: string, body?: unknown, headers?: Record<string, string>): Promise<T>;
|
|
928
|
+
/**
|
|
929
|
+
* PUT request
|
|
930
|
+
*/
|
|
931
|
+
protected put<T>(endpoint: string, body?: unknown, headers?: Record<string, string>): Promise<T>;
|
|
932
|
+
/**
|
|
933
|
+
* DELETE request
|
|
934
|
+
*/
|
|
935
|
+
protected delete<T>(endpoint: string, headers?: Record<string, string>): Promise<T>;
|
|
936
|
+
/**
|
|
937
|
+
* PATCH request
|
|
938
|
+
*/
|
|
939
|
+
protected patch<T>(endpoint: string, body?: unknown, headers?: Record<string, string>): Promise<T>;
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
/**
|
|
943
|
+
* Authentication Service
|
|
944
|
+
* Handles all authentication-related operations with clean separation of concerns
|
|
945
|
+
*/
|
|
946
|
+
declare class AuthService extends BaseService implements IAuthService {
|
|
947
|
+
/**
|
|
948
|
+
* Check if an email exists in the system
|
|
949
|
+
*/
|
|
950
|
+
checkEmailExists(email: string): Promise<EmailExistResponse>;
|
|
951
|
+
/**
|
|
952
|
+
* Login with email and password
|
|
953
|
+
*/
|
|
954
|
+
login(credentials: LoginRequest): Promise<LoginResponse>;
|
|
955
|
+
/**
|
|
956
|
+
* Verify email with verification code
|
|
957
|
+
*/
|
|
958
|
+
verifyEmail(verification: VerifyEmailRequest): Promise<VerifyEmailResponse>;
|
|
959
|
+
/**
|
|
960
|
+
* Get user profile
|
|
961
|
+
*/
|
|
962
|
+
getUserProfile(): Promise<UserProfileResponse>;
|
|
963
|
+
/**
|
|
964
|
+
* Logout user
|
|
965
|
+
*/
|
|
966
|
+
logout(): Promise<void>;
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
/**
|
|
970
|
+
* Authentication API endpoints
|
|
971
|
+
*/
|
|
972
|
+
declare const AUTH_ENDPOINTS: {
|
|
973
|
+
readonly CHECK_EMAIL_EXISTS: (email: string) => string;
|
|
974
|
+
readonly LOGIN: "/auth/user/login";
|
|
975
|
+
readonly VERIFY_EMAIL: "/auth/user/verify";
|
|
976
|
+
readonly GET_USER_PROFILE: "/auth/user/profile";
|
|
977
|
+
readonly LOGOUT: "/auth/logout";
|
|
978
|
+
};
|
|
979
|
+
/**
|
|
980
|
+
* Endpoint builder utility
|
|
981
|
+
*/
|
|
982
|
+
declare class EndpointBuilder {
|
|
983
|
+
static auth: {
|
|
984
|
+
readonly CHECK_EMAIL_EXISTS: (email: string) => string;
|
|
985
|
+
readonly LOGIN: "/auth/user/login";
|
|
986
|
+
readonly VERIFY_EMAIL: "/auth/user/verify";
|
|
987
|
+
readonly GET_USER_PROFILE: "/auth/user/profile";
|
|
988
|
+
readonly LOGOUT: "/auth/logout";
|
|
989
|
+
};
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
/**
|
|
993
|
+
* Authentication Orchestrator Service
|
|
994
|
+
* Orchestrates authentication flow with proper separation of concerns
|
|
995
|
+
* Follows Dependency Inversion Principle (DIP) and Open/Closed Principle (OCP)
|
|
996
|
+
*/
|
|
997
|
+
declare class AuthOrchestrator implements IAuthOrchestrator {
|
|
998
|
+
private authService;
|
|
999
|
+
private eventBus;
|
|
1000
|
+
private tokenManager;
|
|
1001
|
+
private userStorageManager;
|
|
1002
|
+
private errorHandler;
|
|
1003
|
+
private logger;
|
|
1004
|
+
constructor(authService: AuthService, eventBus: EventBus<AuthEvent>, tokenManager?: ITokenManager);
|
|
1005
|
+
/**
|
|
1006
|
+
* Setup Chain of Responsibility for error handling
|
|
1007
|
+
*/
|
|
1008
|
+
private setupErrorHandlerChain;
|
|
1009
|
+
/**
|
|
1010
|
+
* Validate that cookies are supported in the current environment
|
|
1011
|
+
*/
|
|
1012
|
+
private validateCookieSupport;
|
|
1013
|
+
/**
|
|
1014
|
+
* Handle email check to determine if user exists and what action to take
|
|
1015
|
+
*/
|
|
1016
|
+
handleEmailCheck(email: string): Promise<AuthActionResult<EmailExistResponse>>;
|
|
1017
|
+
/**
|
|
1018
|
+
* Handle complete login flow with proper error handling and token management
|
|
1019
|
+
*/
|
|
1020
|
+
handleLoginFlow(credentials: LoginRequest): Promise<AuthActionResult<LoginData>>;
|
|
1021
|
+
/**
|
|
1022
|
+
* Handle email verification flow
|
|
1023
|
+
*/
|
|
1024
|
+
handleEmailVerification(email: string, code: string): Promise<AuthActionResult>;
|
|
1025
|
+
/**
|
|
1026
|
+
* Handle logout flow
|
|
1027
|
+
*/
|
|
1028
|
+
handleLogout(): Promise<AuthActionResult>;
|
|
1029
|
+
/**
|
|
1030
|
+
* Check current authentication status using State Pattern
|
|
1031
|
+
*/
|
|
1032
|
+
checkAuthenticationStatus(): Promise<AuthActionResult>;
|
|
1033
|
+
/**
|
|
1034
|
+
* Get user profile data
|
|
1035
|
+
*/
|
|
1036
|
+
getUserProfileData(): Promise<AuthActionResult>;
|
|
1037
|
+
/**
|
|
1038
|
+
* Get detailed token information
|
|
1039
|
+
*/
|
|
1040
|
+
getTokenInfo(): Promise<AuthActionResult>;
|
|
1041
|
+
}
|
|
1042
|
+
/**
|
|
1043
|
+
* Authentication Orchestrator Factory
|
|
1044
|
+
* Follows Factory Pattern for dependency injection
|
|
1045
|
+
*/
|
|
1046
|
+
declare class AuthOrchestratorFactory {
|
|
1047
|
+
/**
|
|
1048
|
+
* Create AuthOrchestrator with default dependencies
|
|
1049
|
+
*/
|
|
1050
|
+
static create(): AuthOrchestrator;
|
|
1051
|
+
/**
|
|
1052
|
+
* Create AuthOrchestrator with custom dependencies
|
|
1053
|
+
*/
|
|
1054
|
+
static createWithDependencies(authService: AuthService, eventBus: EventBus<AuthEvent>, tokenManager?: ITokenManager): AuthOrchestrator;
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
/**
|
|
1058
|
+
* User Storage Manager Implementation
|
|
1059
|
+
* Handles user profile storage using LocalStorageUtils
|
|
1060
|
+
* Provides a clean interface for user data persistence
|
|
1061
|
+
*/
|
|
1062
|
+
declare class UserStorageManager {
|
|
1063
|
+
private storageUtils;
|
|
1064
|
+
constructor(storageUtils: typeof LocalStorageUtils);
|
|
1065
|
+
/**
|
|
1066
|
+
* Save user profile data to storage
|
|
1067
|
+
*/
|
|
1068
|
+
saveUserProfile(userProfile: UserProfile): boolean;
|
|
1069
|
+
/**
|
|
1070
|
+
* Get user profile data from storage
|
|
1071
|
+
*/
|
|
1072
|
+
getUserProfile(cacheDuration?: number): UserProfile | null;
|
|
1073
|
+
/**
|
|
1074
|
+
* Clear user profile data from storage
|
|
1075
|
+
*/
|
|
1076
|
+
clearUserProfile(): boolean;
|
|
1077
|
+
/**
|
|
1078
|
+
* Check if cached user profile is still valid
|
|
1079
|
+
*/
|
|
1080
|
+
isCacheValid(cacheDuration?: number): boolean;
|
|
1081
|
+
/**
|
|
1082
|
+
* Get user profile with automatic cache validation
|
|
1083
|
+
* Returns null if cache is expired or invalid
|
|
1084
|
+
*/
|
|
1085
|
+
getValidUserProfile(cacheDuration?: number): UserProfile | null;
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
/**
|
|
1089
|
+
* Strategy Pattern: Signup Flow Strategy
|
|
1090
|
+
*/
|
|
1091
|
+
declare class SignupFlowStrategy implements ILoginFlowStrategy {
|
|
1092
|
+
private authService;
|
|
1093
|
+
private tokenManager;
|
|
1094
|
+
constructor(authService: AuthService, tokenManager: ITokenManager);
|
|
1095
|
+
execute(credentials: LoginRequest): Promise<AuthActionResult<LoginData>>;
|
|
1096
|
+
private handleSuccessfulAuthentication;
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
/**
|
|
1100
|
+
* Strategy Pattern: Existing User Login Strategy
|
|
1101
|
+
*/
|
|
1102
|
+
declare class ExistingUserLoginStrategy implements ILoginFlowStrategy {
|
|
1103
|
+
private authService;
|
|
1104
|
+
private tokenManager;
|
|
1105
|
+
constructor(authService: AuthService, tokenManager: ITokenManager);
|
|
1106
|
+
execute(credentials: LoginRequest): Promise<AuthActionResult<LoginData>>;
|
|
1107
|
+
private handleSuccessfulAuthentication;
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
/**
|
|
1111
|
+
* Strategy Pattern: Login Flow Strategy Factory
|
|
1112
|
+
*/
|
|
1113
|
+
declare class LoginFlowStrategyFactory {
|
|
1114
|
+
private static strategies;
|
|
1115
|
+
static createStrategy(action: NextAction, authService: AuthService, tokenManager: ITokenManager): ILoginFlowStrategy;
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
/**
|
|
1119
|
+
* State Pattern: Authenticated State
|
|
1120
|
+
*/
|
|
1121
|
+
declare class AuthenticatedState implements IAuthStatusState {
|
|
1122
|
+
getStatus(tokenManager: ITokenManager): Promise<AuthActionResultSuccess<{
|
|
1123
|
+
isAuthenticated: boolean;
|
|
1124
|
+
hasAccessToken: boolean;
|
|
1125
|
+
hasRefreshToken: boolean;
|
|
1126
|
+
cookiesSupported: boolean;
|
|
1127
|
+
domainInfo: Record<string, string>;
|
|
1128
|
+
}>>;
|
|
1129
|
+
private buildAuthStatus;
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
/**
|
|
1133
|
+
* State Pattern: Unauthenticated State
|
|
1134
|
+
*/
|
|
1135
|
+
declare class UnauthenticatedState implements IAuthStatusState {
|
|
1136
|
+
getStatus(tokenManager: ITokenManager): Promise<AuthActionResultFailure>;
|
|
1137
|
+
private buildAuthStatus;
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
/**
|
|
1141
|
+
* State Pattern: Authentication Status Context
|
|
1142
|
+
*/
|
|
1143
|
+
declare class AuthenticationStatusContext {
|
|
1144
|
+
private static states;
|
|
1145
|
+
static getStatus(tokenManager: ITokenManager): Promise<AuthActionResult>;
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
/**
|
|
1149
|
+
* Command Pattern: Result Creation Commands
|
|
1150
|
+
* Follows Single Responsibility Principle - only responsible for creating AuthResult objects
|
|
1151
|
+
*/
|
|
1152
|
+
declare class AuthResultFactory {
|
|
1153
|
+
/**
|
|
1154
|
+
* Creates a successful authentication result
|
|
1155
|
+
*/
|
|
1156
|
+
static createSuccess<T = unknown>(message: string, data: T): AuthActionResultSuccess<T>;
|
|
1157
|
+
/**
|
|
1158
|
+
* Creates a failed authentication result
|
|
1159
|
+
*/
|
|
1160
|
+
static createFailure(message: string, error?: string | Error | unknown): AuthActionResultFailure;
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
/**
|
|
1164
|
+
* Chain of Responsibility: Base Error Handler
|
|
1165
|
+
*/
|
|
1166
|
+
declare abstract class BaseErrorHandler implements IErrorHandler {
|
|
1167
|
+
private nextHandler?;
|
|
1168
|
+
setNext(handler: IErrorHandler): IErrorHandler;
|
|
1169
|
+
handle(error: unknown, context: string): AuthActionResult;
|
|
1170
|
+
protected abstract canHandle(error: unknown): boolean;
|
|
1171
|
+
protected abstract handleError(error: unknown, context: string): AuthActionResult;
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
/**
|
|
1175
|
+
* Validation Error Handler
|
|
1176
|
+
*/
|
|
1177
|
+
declare class ValidationErrorHandler extends BaseErrorHandler {
|
|
1178
|
+
protected canHandle(error: unknown): boolean;
|
|
1179
|
+
protected handleError(error: unknown, context: string): AuthActionResult;
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
/**
|
|
1183
|
+
* Network Error Handler
|
|
1184
|
+
*/
|
|
1185
|
+
declare class NetworkErrorHandler extends BaseErrorHandler {
|
|
1186
|
+
protected canHandle(error: unknown): boolean;
|
|
1187
|
+
protected handleError(error: unknown, context: string): AuthActionResult;
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
/**
|
|
1191
|
+
* Generic Error Handler
|
|
1192
|
+
*/
|
|
1193
|
+
declare class GenericErrorHandler extends BaseErrorHandler {
|
|
1194
|
+
protected canHandle(_error: unknown): boolean;
|
|
1195
|
+
protected handleError(error: unknown, context: string): AuthActionResult;
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
/**
|
|
1199
|
+
* Development Logger Implementation
|
|
1200
|
+
*/
|
|
1201
|
+
declare class DevelopmentLogger implements ILogger {
|
|
1202
|
+
log(message: string, data?: unknown): void;
|
|
1203
|
+
warn(message: string, data?: unknown): void;
|
|
1204
|
+
error(message: string, data?: unknown): void;
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
/**
|
|
1208
|
+
* Production Logger Implementation
|
|
1209
|
+
*/
|
|
1210
|
+
declare class ProductionLogger implements ILogger {
|
|
1211
|
+
log(_message: string, _data?: unknown): void;
|
|
1212
|
+
warn(_message: string, _data?: unknown): void;
|
|
1213
|
+
error(_message: string, _data?: unknown): void;
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
/**
|
|
1217
|
+
* Lookup Pattern: Logger Factory with Environment-based Strategy
|
|
1218
|
+
*/
|
|
1219
|
+
declare class LoggerFactory {
|
|
1220
|
+
private static loggers;
|
|
1221
|
+
static create(environment?: string): ILogger;
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
/**
|
|
1225
|
+
* User store state interface
|
|
1226
|
+
*/
|
|
1227
|
+
interface UserStoreState {
|
|
1228
|
+
user: UserProfile | null;
|
|
1229
|
+
isLoading: boolean;
|
|
1230
|
+
error: string | null;
|
|
1231
|
+
isAuthenticated: boolean;
|
|
1232
|
+
setUser: (user: UserProfile | null) => void;
|
|
1233
|
+
setLoading: (loading: boolean) => void;
|
|
1234
|
+
setError: (error: string | null) => void;
|
|
1235
|
+
clearUser: () => Promise<void>;
|
|
1236
|
+
refreshUser: (forceRefresh?: boolean) => Promise<void>;
|
|
1237
|
+
_authOrchestrator: AuthOrchestrator;
|
|
1238
|
+
_userStorageManager: UserStorageManager;
|
|
1239
|
+
}
|
|
1240
|
+
/**
|
|
1241
|
+
* Create the user store with Zustand
|
|
1242
|
+
*/
|
|
1243
|
+
declare const useUserStore: zustand.UseBoundStore<Omit<Omit<Omit<zustand.StoreApi<UserStoreState>, "setState" | "devtools"> & {
|
|
1244
|
+
setState(partial: UserStoreState | Partial<UserStoreState> | ((state: UserStoreState) => UserStoreState | Partial<UserStoreState>), replace?: false | undefined, action?: (string | {
|
|
1245
|
+
[x: string]: unknown;
|
|
1246
|
+
[x: number]: unknown;
|
|
1247
|
+
[x: symbol]: unknown;
|
|
1248
|
+
type: string;
|
|
1249
|
+
}) | undefined): void;
|
|
1250
|
+
setState(state: UserStoreState | ((state: UserStoreState) => UserStoreState), replace: true, action?: (string | {
|
|
1251
|
+
[x: string]: unknown;
|
|
1252
|
+
[x: number]: unknown;
|
|
1253
|
+
[x: symbol]: unknown;
|
|
1254
|
+
type: string;
|
|
1255
|
+
}) | undefined): void;
|
|
1256
|
+
devtools: {
|
|
1257
|
+
cleanup: () => void;
|
|
1258
|
+
};
|
|
1259
|
+
}, "subscribe"> & {
|
|
1260
|
+
subscribe: {
|
|
1261
|
+
(listener: (selectedState: UserStoreState, previousSelectedState: UserStoreState) => void): () => void;
|
|
1262
|
+
<U>(selector: (state: UserStoreState) => U, listener: (selectedState: U, previousSelectedState: U) => void, options?: {
|
|
1263
|
+
equalityFn?: ((a: U, b: U) => boolean) | undefined;
|
|
1264
|
+
fireImmediately?: boolean;
|
|
1265
|
+
} | undefined): () => void;
|
|
1266
|
+
};
|
|
1267
|
+
}, "setState"> & {
|
|
1268
|
+
setState(nextStateOrUpdater: UserStoreState | Partial<UserStoreState> | ((state: immer.WritableDraft<UserStoreState>) => void), shouldReplace?: false, action?: (string | {
|
|
1269
|
+
[x: string]: unknown;
|
|
1270
|
+
[x: number]: unknown;
|
|
1271
|
+
[x: symbol]: unknown;
|
|
1272
|
+
type: string;
|
|
1273
|
+
}) | undefined): void;
|
|
1274
|
+
setState(nextStateOrUpdater: UserStoreState | ((state: immer.WritableDraft<UserStoreState>) => void), shouldReplace: true, action?: (string | {
|
|
1275
|
+
[x: string]: unknown;
|
|
1276
|
+
[x: number]: unknown;
|
|
1277
|
+
[x: symbol]: unknown;
|
|
1278
|
+
type: string;
|
|
1279
|
+
}) | undefined): void;
|
|
1280
|
+
}>;
|
|
1281
|
+
/**
|
|
1282
|
+
* Selectors for accessing store state
|
|
1283
|
+
* These provide a clean interface and are optimized for performance using useShallow
|
|
1284
|
+
*/
|
|
1285
|
+
declare const userSelectors: {
|
|
1286
|
+
useUser: () => UserProfile | null;
|
|
1287
|
+
useIsAuthenticated: () => boolean;
|
|
1288
|
+
useIsLoading: () => boolean;
|
|
1289
|
+
useError: () => string | null;
|
|
1290
|
+
useUserState: () => {
|
|
1291
|
+
user: UserProfile | null;
|
|
1292
|
+
isAuthenticated: boolean;
|
|
1293
|
+
isLoading: boolean;
|
|
1294
|
+
error: string | null;
|
|
1295
|
+
};
|
|
1296
|
+
useActions: () => {
|
|
1297
|
+
setUser: (user: UserProfile | null) => void;
|
|
1298
|
+
setLoading: (loading: boolean) => void;
|
|
1299
|
+
setError: (error: string | null) => void;
|
|
1300
|
+
clearUser: () => Promise<void>;
|
|
1301
|
+
refreshUser: (forceRefresh?: boolean) => Promise<void>;
|
|
1302
|
+
};
|
|
1303
|
+
};
|
|
1304
|
+
|
|
1305
|
+
declare const AuthFlowContainer: React__default.FC;
|
|
1306
|
+
|
|
1307
|
+
declare const AuthFlowModal: ({ children }: {
|
|
1308
|
+
children: React__default.ReactNode;
|
|
1309
|
+
}) => React__default.JSX.Element;
|
|
1310
|
+
|
|
1311
|
+
/**
|
|
1312
|
+
* Auth Initializer Component
|
|
1313
|
+
* Initializes the auth event bus and user store without requiring a provider
|
|
1314
|
+
*/
|
|
1315
|
+
declare const AuthInitializer: ({ children }: {
|
|
1316
|
+
children: React.ReactNode;
|
|
1317
|
+
}) => React.ReactElement;
|
|
1318
|
+
|
|
1319
|
+
declare const BaseForm: <T>({ title, description, fields, submitButtonText, onSubmit, isLoading, error, success, form, additionalActions, showAlerts, initialValues }: BaseFormProps<T>) => React__default.JSX.Element;
|
|
1320
|
+
|
|
1321
|
+
declare const EmailStep: React__default.FC<EmailStepProps>;
|
|
1322
|
+
|
|
1323
|
+
declare const PasswordStep: React__default.FC<PasswordStepProps>;
|
|
1324
|
+
|
|
1325
|
+
declare const VerificationStep: React__default.FC<VerificationStepProps>;
|
|
1326
|
+
|
|
1327
|
+
declare const getEmailStepComponent: StepComponent;
|
|
1328
|
+
declare const getPasswordStepComponent: StepComponent;
|
|
1329
|
+
declare const getVerificationStepComponent: StepComponent;
|
|
1330
|
+
declare const createStepRegistry: () => StepRegistry;
|
|
1331
|
+
declare const createPropsFactoryRegistry: ({ baseProps, handlers, state, configs }: StepRegistryParams) => StepPropsFactoryRegistry;
|
|
1332
|
+
declare const useStepRenderer: () => {
|
|
1333
|
+
getStepComponent: (step: AuthFlowStep) => StepComponent | null;
|
|
1334
|
+
};
|
|
1335
|
+
|
|
1336
|
+
declare const AlertDisplay: ({ error, success }: AlertDisplayProps) => React__default.JSX.Element | null;
|
|
1337
|
+
|
|
1338
|
+
declare const FormHeader: ({ title, description }: FormHeaderProps) => React__default.JSX.Element;
|
|
1339
|
+
|
|
1340
|
+
declare const FormFields: ({ fields }: FormFieldsProps) => React__default.JSX.Element[];
|
|
1341
|
+
|
|
1342
|
+
declare const ProfileStateRenderer: () => React__default.JSX.Element;
|
|
1343
|
+
|
|
1344
|
+
/**
|
|
1345
|
+
* Cross-Tab Authentication Demo Component
|
|
1346
|
+
* Demonstrates the cross-tab authentication event handling
|
|
1347
|
+
*/
|
|
1348
|
+
declare const CrossTabDemo: React__default.FC;
|
|
1349
|
+
|
|
1350
|
+
/**
|
|
1351
|
+
* Custom hook for managing authentication action states and execution.
|
|
1352
|
+
*
|
|
1353
|
+
* This hook implements the DRY principle by centralizing common logic for:
|
|
1354
|
+
* - Loading state management
|
|
1355
|
+
* - Error handling and transformation
|
|
1356
|
+
* - Success state management
|
|
1357
|
+
* - Async action execution with consistent patterns
|
|
1358
|
+
*
|
|
1359
|
+
* @returns {UseAuthActionHandler} Object containing state and action handlers
|
|
1360
|
+
*/
|
|
1361
|
+
declare const useAuthActionHandler: () => UseAuthActionHandler;
|
|
1362
|
+
|
|
1363
|
+
/**
|
|
1364
|
+
* Custom hook for managing stepper logic with full type safety.
|
|
1365
|
+
*
|
|
1366
|
+
* This hook implements the Single Responsibility Principle by focusing solely on
|
|
1367
|
+
* stepper state management and navigation logic.
|
|
1368
|
+
*
|
|
1369
|
+
* Features:
|
|
1370
|
+
* - Type-safe step management
|
|
1371
|
+
* - Automatic progress calculation
|
|
1372
|
+
* - Step validation
|
|
1373
|
+
* - Navigation helpers
|
|
1374
|
+
* - Reset functionality
|
|
1375
|
+
*
|
|
1376
|
+
* @param config - Step configuration object
|
|
1377
|
+
* @returns Stepper state, actions, and helper functions
|
|
1378
|
+
*/
|
|
1379
|
+
declare const useStepper: <T extends string>(config: StepConfig<T>) => UseStepperReturn<T>;
|
|
1380
|
+
|
|
1381
|
+
declare function useStepRegistry({ baseProps: actionState, handlers, state, configs, getStepComponent, stepperState }: UseStepRegistryParams): {
|
|
1382
|
+
SelectedComponent: React$1.ComponentType<AnyStepProps>;
|
|
1383
|
+
stepProps: AnyStepProps | {
|
|
1384
|
+
isLoading: boolean | undefined;
|
|
1385
|
+
error: string | undefined;
|
|
1386
|
+
success: string | undefined;
|
|
1387
|
+
};
|
|
1388
|
+
};
|
|
1389
|
+
|
|
1390
|
+
declare const useAuthEventBus: ({ onLoggedOut, onLoggedIn }?: UseAuthEventBusProps) => void;
|
|
1391
|
+
|
|
1392
|
+
declare function useSharedEventBus(): BroadcastChannelEventBus<AuthEvent>;
|
|
1393
|
+
|
|
1394
|
+
declare function useSignInRequiredParams(): void;
|
|
1395
|
+
|
|
1396
|
+
/**
|
|
1397
|
+
* Main hook for accessing user state and actions
|
|
1398
|
+
* This is the primary interface components should use
|
|
1399
|
+
*/
|
|
1400
|
+
declare const useUser: () => {
|
|
1401
|
+
setUser: (user: UserProfile | null) => void;
|
|
1402
|
+
setLoading: (loading: boolean) => void;
|
|
1403
|
+
setError: (error: string | null) => void;
|
|
1404
|
+
clearUser: () => Promise<void>;
|
|
1405
|
+
refreshUser: (forceRefresh?: boolean) => Promise<void>;
|
|
1406
|
+
user: UserProfile | null;
|
|
1407
|
+
isAuthenticated: boolean;
|
|
1408
|
+
isLoading: boolean;
|
|
1409
|
+
error: string | null;
|
|
1410
|
+
};
|
|
1411
|
+
/**
|
|
1412
|
+
* Hook for accessing only user data (optimized for components that only need state)
|
|
1413
|
+
*/
|
|
1414
|
+
declare const useUserData: () => {
|
|
1415
|
+
user: UserProfile | null;
|
|
1416
|
+
isAuthenticated: boolean;
|
|
1417
|
+
isLoading: boolean;
|
|
1418
|
+
error: string | null;
|
|
1419
|
+
};
|
|
1420
|
+
/**
|
|
1421
|
+
* Hook for accessing only user actions (optimized for components that only need actions)
|
|
1422
|
+
*/
|
|
1423
|
+
declare const useUserActions: () => {
|
|
1424
|
+
setUser: (user: UserProfile | null) => void;
|
|
1425
|
+
setLoading: (loading: boolean) => void;
|
|
1426
|
+
setError: (error: string | null) => void;
|
|
1427
|
+
clearUser: () => Promise<void>;
|
|
1428
|
+
refreshUser: (forceRefresh?: boolean) => Promise<void>;
|
|
1429
|
+
};
|
|
1430
|
+
/**
|
|
1431
|
+
* Hook for checking authentication status
|
|
1432
|
+
*/
|
|
1433
|
+
declare const useAuth: () => {
|
|
1434
|
+
isAuthenticated: boolean;
|
|
1435
|
+
isLoading: boolean;
|
|
1436
|
+
error: string | null;
|
|
1437
|
+
user: UserProfile | null;
|
|
1438
|
+
};
|
|
1439
|
+
/**
|
|
1440
|
+
* Hook that initializes user authentication and sets up event handling
|
|
1441
|
+
* Used for app-level initialization without requiring React Context
|
|
1442
|
+
*/
|
|
1443
|
+
declare const useAuthInitializer: () => {
|
|
1444
|
+
setUser: (user: UserProfile | null) => void;
|
|
1445
|
+
setLoading: (loading: boolean) => void;
|
|
1446
|
+
setError: (error: string | null) => void;
|
|
1447
|
+
clearUser: () => Promise<void>;
|
|
1448
|
+
refreshUser: (forceRefresh?: boolean) => Promise<void>;
|
|
1449
|
+
user: UserProfile | null;
|
|
1450
|
+
isAuthenticated: boolean;
|
|
1451
|
+
isLoading: boolean;
|
|
1452
|
+
error: string | null;
|
|
1453
|
+
};
|
|
1454
|
+
/**
|
|
1455
|
+
* Specialized hooks for specific use cases
|
|
1456
|
+
*/
|
|
1457
|
+
/**
|
|
1458
|
+
* Hook for components that only need to know if user is authenticated
|
|
1459
|
+
*/
|
|
1460
|
+
declare const useIsAuthenticated: () => boolean;
|
|
1461
|
+
/**
|
|
1462
|
+
* Hook for components that only need loading state
|
|
1463
|
+
*/
|
|
1464
|
+
declare const useUserLoading: () => boolean;
|
|
1465
|
+
/**
|
|
1466
|
+
* Hook for components that only need error state
|
|
1467
|
+
*/
|
|
1468
|
+
declare const useUserError: () => string | null;
|
|
1469
|
+
/**
|
|
1470
|
+
* Hook for components that only need user profile data
|
|
1471
|
+
*/
|
|
1472
|
+
declare const useUserProfile: () => UserProfile | null;
|
|
1473
|
+
/**
|
|
1474
|
+
* Hook for logout functionality with proper cleanup
|
|
1475
|
+
*/
|
|
1476
|
+
declare const useLogout: () => () => Promise<void>;
|
|
1477
|
+
/**
|
|
1478
|
+
* Hook for refreshing user data
|
|
1479
|
+
*/
|
|
1480
|
+
declare const useRefreshUser: () => (force?: boolean) => Promise<void>;
|
|
1481
|
+
|
|
1482
|
+
/**
|
|
1483
|
+
* Custom hook to manage AuthFlowModal state
|
|
1484
|
+
* Handles initial loading and modal visibility based on auth events
|
|
1485
|
+
*/
|
|
1486
|
+
declare const useAuthFlowModal: () => {
|
|
1487
|
+
isModalOpen: boolean;
|
|
1488
|
+
isInitialLoading: boolean;
|
|
1489
|
+
openModal: () => void;
|
|
1490
|
+
};
|
|
1491
|
+
|
|
1492
|
+
export { AUTH_ENDPOINTS, AlertDisplay, type AlertDisplayProps, type AnyStepProps, type ApiErrorResponse, type ApiKeyConfig, type AuthActionCallbacks, type AuthActionOptions, type AuthActionResult, type AuthActionResultFailure, type AuthActionResultSuccess, type AuthActionState, type AuthEvent, AuthEventType, AuthFlowContainer, AuthFlowModal, AuthFlowStep, AuthInitializer, AuthOrchestrator, AuthOrchestratorFactory, AuthResultFactory, AuthService, type AuthState, AuthenticatedState, type AuthenticatedStateProps, AuthenticationStatusContext, type BaseComponentProps, BaseErrorHandler, BaseEventBus, BaseForm, type BaseFormField, type BaseFormProps, type BaseResponse, BaseService, type BaseStepProps, BroadcastChannelEventBus, Channel, CookieUtils, CrossTabBehaviorConfig, CrossTabBehaviorHandler, CrossTabDemo, DevelopmentLogger, EMAIL_SUBMISSION_NAVIGATION, type EmailCheckResult, type EmailExistResponse, EmailStep, type EmailStepProps, EndpointBuilder, type EventBus, ExistingUserLoginStrategy, FormFields, type FormFieldsProps, FormHeader, type FormHeaderProps, GenericErrorHandler, HttpClient, type HttpClientConfig, type HttpError, HttpMethod, type HttpRequestOptions, type HttpResponse, type IAuthOrchestrator, type IAuthService, type IAuthStatusState, type IErrorHandler, type ILogger, type ILoginFlowStrategy, type ITokenManager, LocalStorageUtils, LoggerFactory, type LoginData, LoginFlowStrategyFactory, type LoginRequest, type LoginResponse, MiddlewareConfig, type MiddlewareContext, type MiddlewareHandler, NavigationAction, NetworkErrorHandler, NextAction, PASSWORD_SUBMISSION_NAVIGATION, PageType, PageTypePatterns, PasswordStep, type PasswordStepProps, ProductionLogger, ProfileStateRenderer, ProfileUIState, type PropsFactory, RoleType, SignupFlowStrategy, type Step, type StepComponent, type StepComponentRetriever, type StepConfig, type StepPropsFactoryRegistry, type StepRegistry, type StepRegistryBaseProps, type StepRegistryConfigs, type StepRegistryHandlers, type StepRegistryParams, type StepRegistryState, type StepperActions, type StepperState$1 as StepperState, type Subscription, TokenManager, UnauthenticatedState, type UseAuthActionHandler, type UseAuthEventBusProps, type UseFormSubmissionProps, type UseStepRegistryParams, type UseStepperReturn, type UserProfile, type UserProfileResponse, type UserSession, type UserState, UserStorageManager, type UserStoreState, VERIFICATION_SUBMISSION_NAVIGATION, ValidationErrorHandler, VerificationStep, type VerificationStepProps, type VerifyEmailRequest, type VerifyEmailResponse, config, createAuthSteps, createPropsFactoryRegistry, createStepRegistry, getAuthPageStepMessage, getEmailField, getEmailStepComponent, getPasswordField, getPasswordStepComponent, getStepForEmailSubmission, getStepForPasswordSubmission, getStepForVerificationSubmission, getStepProgressMessage, getVerificationField, getVerificationStepComponent, middlewareMatcher, useAuth, useAuthActionHandler, useAuthEventBus, useAuthFlowModal, useAuthInitializer, useIsAuthenticated, useLogout, useRefreshUser, useSharedEventBus, useSignInRequiredParams, useStepRegistry, useStepRenderer, useStepper, useUser, useUserActions, useUserData, useUserError, useUserLoading, useUserProfile, useUserStore, userSelectors };
|