@digilogiclabs/saas-factory-auth 0.2.0 → 0.3.2
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/components/native/index.js +603 -0
- package/dist/components/native/index.js.map +1 -0
- package/dist/components/native/index.mjs +595 -0
- package/dist/components/native/index.mjs.map +1 -0
- package/dist/components/web/index.d.mts +39 -0
- package/dist/components/web/index.d.ts +39 -0
- package/dist/components/web/index.js +417 -0
- package/dist/components/web/index.js.map +1 -0
- package/dist/components/web/index.mjs +411 -0
- package/dist/components/web/index.mjs.map +1 -0
- package/dist/index.d.mts +582 -56
- package/dist/index.d.ts +582 -56
- package/dist/index.js +1833 -91
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1809 -89
- package/dist/index.mjs.map +1 -1
- package/package.json +139 -93
- package/src/components/native/index.d.ts +29 -0
- package/README.md +0 -148
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,174 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as _supabase_auth_js from '@supabase/auth-js';
|
|
2
2
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
|
+
import * as react from 'react';
|
|
3
4
|
import { ReactNode } from 'react';
|
|
4
5
|
import * as zustand from 'zustand';
|
|
5
|
-
import
|
|
6
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Common user interface that abstracts user data across different authentication providers
|
|
10
|
+
*/
|
|
11
|
+
interface CommonUser {
|
|
12
|
+
/** Unique user identifier */
|
|
13
|
+
id: string;
|
|
14
|
+
/** User's email address */
|
|
15
|
+
email: string | undefined;
|
|
16
|
+
/** User's display name */
|
|
17
|
+
displayName?: string | null;
|
|
18
|
+
/** URL to user's profile photo */
|
|
19
|
+
photoURL?: string | null;
|
|
20
|
+
/** User roles for authorization */
|
|
21
|
+
roles?: string[];
|
|
22
|
+
/** Provider-specific metadata */
|
|
23
|
+
metadata: Record<string, any>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Authentication session interface that wraps user data
|
|
27
|
+
*/
|
|
28
|
+
interface AuthSession {
|
|
29
|
+
/** Current authenticated user */
|
|
30
|
+
user: CommonUser | null;
|
|
31
|
+
/** Session expiration timestamp (optional) */
|
|
32
|
+
expiresAt?: number;
|
|
33
|
+
/** Access token (optional, provider-specific) */
|
|
34
|
+
accessToken?: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Authentication error types for better error handling
|
|
38
|
+
*/
|
|
39
|
+
declare enum AuthErrorType {
|
|
40
|
+
INVALID_CREDENTIALS = "INVALID_CREDENTIALS",
|
|
41
|
+
USER_NOT_FOUND = "USER_NOT_FOUND",
|
|
42
|
+
EMAIL_ALREADY_EXISTS = "EMAIL_ALREADY_EXISTS",
|
|
43
|
+
WEAK_PASSWORD = "WEAK_PASSWORD",
|
|
44
|
+
NETWORK_ERROR = "NETWORK_ERROR",
|
|
45
|
+
PROVIDER_ERROR = "PROVIDER_ERROR",
|
|
46
|
+
CONFIGURATION_ERROR = "CONFIGURATION_ERROR",
|
|
47
|
+
VALIDATION_ERROR = "VALIDATION_ERROR"
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Custom authentication error class
|
|
51
|
+
*/
|
|
52
|
+
declare class AuthError extends Error {
|
|
53
|
+
readonly type: AuthErrorType;
|
|
54
|
+
readonly originalError?: any | undefined;
|
|
55
|
+
readonly context?: Record<string, any> | undefined;
|
|
56
|
+
readonly timestamp: Date;
|
|
57
|
+
readonly code: string;
|
|
58
|
+
constructor(type: AuthErrorType, message: string, originalError?: any | undefined, context?: Record<string, any> | undefined);
|
|
59
|
+
/**
|
|
60
|
+
* Convert error to JSON for logging/debugging
|
|
61
|
+
*/
|
|
62
|
+
toJSON(): {
|
|
63
|
+
name: string;
|
|
64
|
+
type: AuthErrorType;
|
|
65
|
+
code: string;
|
|
66
|
+
message: string;
|
|
67
|
+
timestamp: string;
|
|
68
|
+
context: Record<string, any> | undefined;
|
|
69
|
+
originalError: {
|
|
70
|
+
name: any;
|
|
71
|
+
message: any;
|
|
72
|
+
code: any;
|
|
73
|
+
} | undefined;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Check if error is of a specific type
|
|
77
|
+
*/
|
|
78
|
+
isType(type: AuthErrorType): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Check if error is retryable
|
|
81
|
+
*/
|
|
82
|
+
isRetryable(): boolean;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Authentication state change events
|
|
86
|
+
*/
|
|
87
|
+
declare enum AuthEvent {
|
|
88
|
+
SIGNED_IN = "SIGNED_IN",
|
|
89
|
+
SIGNED_OUT = "SIGNED_OUT",
|
|
90
|
+
TOKEN_REFRESHED = "TOKEN_REFRESHED",
|
|
91
|
+
USER_UPDATED = "USER_UPDATED"
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* OAuth provider types
|
|
95
|
+
*/
|
|
96
|
+
type OAuthProvider = 'google' | 'github' | 'facebook' | 'twitter' | 'discord' | 'apple';
|
|
97
|
+
/**
|
|
98
|
+
* Authentication provider interface that abstracts authentication operations
|
|
99
|
+
* across different backends (Supabase, Firebase, etc.)
|
|
100
|
+
*/
|
|
101
|
+
interface IAuthProvider {
|
|
102
|
+
/**
|
|
103
|
+
* Sign in with email and password
|
|
104
|
+
* @param email User's email address
|
|
105
|
+
* @param password User's password (required for email/password authentication)
|
|
106
|
+
* @returns Promise resolving to the authenticated user or null
|
|
107
|
+
* @throws AuthError when authentication fails
|
|
108
|
+
*/
|
|
109
|
+
signIn(email: string, password?: string): Promise<CommonUser | null>;
|
|
110
|
+
/**
|
|
111
|
+
* Sign up with email and password
|
|
112
|
+
* @param email User's email address
|
|
113
|
+
* @param password User's password (required for email/password authentication)
|
|
114
|
+
* @returns Promise resolving to the created user or null
|
|
115
|
+
* @throws AuthError when sign up fails
|
|
116
|
+
*/
|
|
117
|
+
signUp(email: string, password?: string): Promise<CommonUser | null>;
|
|
118
|
+
/**
|
|
119
|
+
* Sign in with OAuth provider
|
|
120
|
+
* @param provider OAuth provider name
|
|
121
|
+
* @param redirectTo Optional redirect URL after authentication
|
|
122
|
+
* @returns Promise that resolves when OAuth flow is initiated
|
|
123
|
+
* @throws AuthError when OAuth flow fails to initiate
|
|
124
|
+
*/
|
|
125
|
+
signInWithOAuth(provider: OAuthProvider, redirectTo?: string): Promise<void>;
|
|
126
|
+
/**
|
|
127
|
+
* Sign in with magic link (passwordless authentication)
|
|
128
|
+
* @param email User's email address
|
|
129
|
+
* @param redirectTo Optional redirect URL after email verification
|
|
130
|
+
* @returns Promise that resolves when magic link is sent
|
|
131
|
+
* @throws AuthError when magic link sending fails
|
|
132
|
+
*/
|
|
133
|
+
signInWithMagicLink(email: string, redirectTo?: string): Promise<void>;
|
|
134
|
+
/**
|
|
135
|
+
* Sign out the current user
|
|
136
|
+
* @returns Promise that resolves when sign out is complete
|
|
137
|
+
* @throws AuthError when sign out fails
|
|
138
|
+
*/
|
|
139
|
+
signOut(): Promise<void>;
|
|
140
|
+
/**
|
|
141
|
+
* Send password reset email
|
|
142
|
+
* @param email User's email address
|
|
143
|
+
* @returns Promise that resolves when reset email is sent
|
|
144
|
+
* @throws AuthError when password reset fails
|
|
145
|
+
*/
|
|
146
|
+
resetPassword(email: string): Promise<void>;
|
|
147
|
+
/**
|
|
148
|
+
* Get the current authenticated user
|
|
149
|
+
* @returns Promise resolving to the current user or null if not authenticated
|
|
150
|
+
* @throws AuthError when user retrieval fails
|
|
151
|
+
*/
|
|
152
|
+
getUser(): Promise<CommonUser | null>;
|
|
153
|
+
/**
|
|
154
|
+
* Listen for authentication state changes
|
|
155
|
+
* @param callback Function called when auth state changes
|
|
156
|
+
* @returns Object containing subscription data for cleanup
|
|
157
|
+
*/
|
|
158
|
+
onAuthStateChange(callback: (event: AuthEvent, session: AuthSession | null) => void): {
|
|
159
|
+
data: {
|
|
160
|
+
subscription: any;
|
|
161
|
+
} | {
|
|
162
|
+
unsubscribe: () => void;
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* Validate provider configuration
|
|
167
|
+
* @returns Promise that resolves if configuration is valid
|
|
168
|
+
* @throws AuthError when configuration is invalid
|
|
169
|
+
*/
|
|
170
|
+
validateConfiguration?(): Promise<void>;
|
|
171
|
+
}
|
|
6
172
|
|
|
7
173
|
type AuthMode = 'signIn' | 'signUp' | 'resetPassword' | 'magicLink';
|
|
8
174
|
interface UserRole {
|
|
@@ -26,78 +192,438 @@ interface AuthFormProps {
|
|
|
26
192
|
onSuccess?: () => void;
|
|
27
193
|
onError?: (error: Error) => void;
|
|
28
194
|
redirectTo?: string;
|
|
29
|
-
providers?:
|
|
195
|
+
providers?: OAuthProvider[];
|
|
30
196
|
allowMagicLink?: boolean;
|
|
31
197
|
}
|
|
32
198
|
interface AuthState {
|
|
33
|
-
user:
|
|
199
|
+
user: CommonUser | null;
|
|
34
200
|
loading: boolean;
|
|
35
201
|
error: Error | null;
|
|
36
202
|
}
|
|
37
203
|
interface AuthStore extends AuthState {
|
|
38
|
-
signIn: (email: string, password
|
|
39
|
-
signUp: (email: string, password
|
|
40
|
-
signInWithOAuth: (provider:
|
|
204
|
+
signIn: (email: string, password?: string) => Promise<void>;
|
|
205
|
+
signUp: (email: string, password?: string) => Promise<void>;
|
|
206
|
+
signInWithOAuth: (provider: OAuthProvider, redirectTo?: string) => Promise<void>;
|
|
41
207
|
signInWithMagicLink: (email: string, redirectTo?: string) => Promise<void>;
|
|
42
208
|
signOut: () => Promise<void>;
|
|
43
209
|
resetPassword: (email: string) => Promise<void>;
|
|
44
|
-
|
|
210
|
+
getUser: () => Promise<CommonUser | null>;
|
|
211
|
+
onAuthStateChange: (callback: (event: any, session: any) => void) => any;
|
|
212
|
+
updateUser: (user: CommonUser | null) => void;
|
|
45
213
|
setLoading: (loading: boolean) => void;
|
|
46
214
|
setError: (error: Error | null) => void;
|
|
47
215
|
}
|
|
48
216
|
|
|
49
|
-
|
|
217
|
+
interface IAuthStorage {
|
|
218
|
+
getItem(key: string): Promise<string | null>;
|
|
219
|
+
setItem(key: string, value: string): Promise<void>;
|
|
220
|
+
removeItem(key: string): Promise<void>;
|
|
221
|
+
}
|
|
222
|
+
declare class WebAuthStorage implements IAuthStorage {
|
|
223
|
+
getItem(key: string): Promise<string | null>;
|
|
224
|
+
setItem(key: string, value: string): Promise<void>;
|
|
225
|
+
removeItem(key: string): Promise<void>;
|
|
226
|
+
}
|
|
227
|
+
declare class NativeAuthStorage implements IAuthStorage {
|
|
228
|
+
private AsyncStorage;
|
|
229
|
+
constructor();
|
|
230
|
+
getItem(key: string): Promise<string | null>;
|
|
231
|
+
setItem(key: string, value: string): Promise<void>;
|
|
232
|
+
removeItem(key: string): Promise<void>;
|
|
233
|
+
}
|
|
234
|
+
declare const createAuthStorage: () => IAuthStorage;
|
|
50
235
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
236
|
+
/**
|
|
237
|
+
* Supported authentication provider types
|
|
238
|
+
*/
|
|
239
|
+
type AuthProviderType = 'supabase' | 'firebase';
|
|
240
|
+
/**
|
|
241
|
+
* Configuration interface for provider factory
|
|
242
|
+
*/
|
|
243
|
+
interface AuthProviderConfig {
|
|
244
|
+
/** Provider type to use */
|
|
245
|
+
type: AuthProviderType;
|
|
246
|
+
/** Whether to validate configuration on creation */
|
|
247
|
+
validateConfig?: boolean;
|
|
248
|
+
/** Whether to use singleton pattern */
|
|
249
|
+
useSingleton?: boolean;
|
|
250
|
+
/** Custom storage implementation (optional) */
|
|
251
|
+
storage?: IAuthStorage;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Factory class for creating authentication providers with improved patterns
|
|
255
|
+
*/
|
|
256
|
+
declare class AuthProviderFactory {
|
|
257
|
+
private static instances;
|
|
258
|
+
/**
|
|
259
|
+
* Gets provider based on environment variables (auto-detection)
|
|
260
|
+
* @param config Optional configuration overrides
|
|
261
|
+
* @returns Authentication provider instance
|
|
262
|
+
*/
|
|
263
|
+
static getProviderFromEnvironment(config?: Partial<AuthProviderConfig>): Promise<IAuthProvider>;
|
|
264
|
+
/**
|
|
265
|
+
* Gets provider instance with configuration
|
|
266
|
+
* @param config Provider configuration
|
|
267
|
+
* @returns Authentication provider instance
|
|
268
|
+
*/
|
|
269
|
+
static getProvider(config: AuthProviderConfig): Promise<IAuthProvider>;
|
|
270
|
+
/**
|
|
271
|
+
* Creates a new provider instance without caching
|
|
272
|
+
* @param type Provider type
|
|
273
|
+
* @param storage Optional custom storage implementation
|
|
274
|
+
* @returns Authentication provider instance
|
|
275
|
+
*/
|
|
276
|
+
static createProvider(type: AuthProviderType, storage?: IAuthStorage): IAuthProvider;
|
|
277
|
+
/**
|
|
278
|
+
* Detects provider type from environment variables
|
|
279
|
+
* @returns Detected provider type
|
|
280
|
+
*/
|
|
281
|
+
private static detectProviderFromEnvironment;
|
|
282
|
+
/**
|
|
283
|
+
* Gets explicit provider from environment variables (platform-agnostic)
|
|
284
|
+
*/
|
|
285
|
+
private static getExplicitProvider;
|
|
286
|
+
/**
|
|
287
|
+
* Validates if a string is a valid provider type
|
|
288
|
+
* @param type String to validate
|
|
289
|
+
* @returns True if valid provider type
|
|
290
|
+
*/
|
|
291
|
+
private static isValidProviderType;
|
|
292
|
+
/**
|
|
293
|
+
* Gets list of supported provider types
|
|
294
|
+
* @returns Array of supported provider types
|
|
295
|
+
*/
|
|
296
|
+
static getSupportedProviders(): AuthProviderType[];
|
|
297
|
+
/**
|
|
298
|
+
* Checks if a provider type is supported
|
|
299
|
+
* @param type Provider type to check
|
|
300
|
+
* @returns True if supported
|
|
301
|
+
*/
|
|
302
|
+
static isProviderSupported(type: string): type is AuthProviderType;
|
|
303
|
+
/**
|
|
304
|
+
* Clears singleton instances (useful for testing)
|
|
305
|
+
*/
|
|
306
|
+
static clearInstances(): void;
|
|
307
|
+
/**
|
|
308
|
+
* Gets current singleton instances (useful for debugging)
|
|
309
|
+
* @returns Map of current instances
|
|
310
|
+
*/
|
|
311
|
+
static getInstances(): Map<AuthProviderType, IAuthProvider>;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Supabase authentication provider implementation
|
|
316
|
+
*/
|
|
317
|
+
declare class SupabaseAuthProvider implements IAuthProvider {
|
|
318
|
+
private client;
|
|
319
|
+
private storage;
|
|
320
|
+
constructor(storage: IAuthStorage);
|
|
321
|
+
/**
|
|
322
|
+
* Validates Supabase configuration
|
|
323
|
+
*/
|
|
324
|
+
validateConfiguration(): Promise<void>;
|
|
325
|
+
signIn(email: string, password?: string): Promise<CommonUser | null>;
|
|
326
|
+
signUp(email: string, password?: string): Promise<CommonUser | null>;
|
|
327
|
+
signInWithOAuth(provider: OAuthProvider, redirectTo?: string): Promise<void>;
|
|
328
|
+
signInWithMagicLink(email: string, redirectTo?: string): Promise<void>;
|
|
329
|
+
signOut(): Promise<void>;
|
|
330
|
+
resetPassword(email: string): Promise<void>;
|
|
331
|
+
getUser(): Promise<CommonUser | null>;
|
|
332
|
+
onAuthStateChange(callback: (event: AuthEvent, session: AuthSession | null) => void): {
|
|
333
|
+
data: {
|
|
334
|
+
subscription: any;
|
|
335
|
+
} | {
|
|
336
|
+
unsubscribe: () => void;
|
|
93
337
|
};
|
|
94
|
-
|
|
95
|
-
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Firebase authentication provider implementation
|
|
343
|
+
*/
|
|
344
|
+
declare class FirebaseAuthProvider implements IAuthProvider {
|
|
345
|
+
private app;
|
|
346
|
+
private auth;
|
|
347
|
+
private storage;
|
|
348
|
+
constructor(storage: IAuthStorage);
|
|
349
|
+
/**
|
|
350
|
+
* Validates Firebase configuration
|
|
351
|
+
*/
|
|
352
|
+
validateConfiguration(): Promise<void>;
|
|
353
|
+
signIn(email: string, password?: string): Promise<CommonUser | null>;
|
|
354
|
+
signUp(email: string, password?: string): Promise<CommonUser | null>;
|
|
355
|
+
signInWithOAuth(provider: OAuthProvider, redirectTo?: string): Promise<void>;
|
|
356
|
+
signInWithMagicLink(email: string, redirectTo?: string): Promise<void>;
|
|
357
|
+
signOut(): Promise<void>;
|
|
358
|
+
resetPassword(email: string): Promise<void>;
|
|
359
|
+
getUser(): Promise<CommonUser | null>;
|
|
360
|
+
onAuthStateChange(callback: (event: AuthEvent, session: AuthSession | null) => void): {
|
|
361
|
+
data: {
|
|
362
|
+
subscription: any;
|
|
363
|
+
} | {
|
|
364
|
+
unsubscribe: () => void;
|
|
96
365
|
};
|
|
97
366
|
};
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
declare const useAuth: () => {
|
|
370
|
+
signIn: (email: string, password?: string) => Promise<void>;
|
|
371
|
+
signUp: (email: string, password?: string) => Promise<void>;
|
|
372
|
+
signInWithOAuth: (provider: OAuthProvider, redirectTo?: string) => Promise<void>;
|
|
373
|
+
signInWithMagicLink: (email: string, redirectTo?: string) => Promise<void>;
|
|
374
|
+
signOut: () => Promise<void>;
|
|
375
|
+
resetPassword: (email: string) => Promise<void>;
|
|
376
|
+
getUser: () => Promise<CommonUser | null>;
|
|
377
|
+
onAuthStateChange: (callback: (event: any, session: any) => void) => any;
|
|
378
|
+
updateUser: (user: CommonUser | null) => void;
|
|
379
|
+
setLoading: (loading: boolean) => void;
|
|
380
|
+
setError: (error: Error | null) => void;
|
|
381
|
+
user: CommonUser | null;
|
|
382
|
+
loading: boolean;
|
|
383
|
+
error: Error | null;
|
|
98
384
|
};
|
|
99
385
|
|
|
100
|
-
|
|
101
|
-
|
|
386
|
+
interface UseAuthFormOptions {
|
|
387
|
+
onSuccess?: () => void;
|
|
388
|
+
onError?: (error: AuthError) => void;
|
|
389
|
+
redirectUrl?: string;
|
|
390
|
+
}
|
|
391
|
+
interface AuthFormState {
|
|
392
|
+
email: string;
|
|
393
|
+
password: string;
|
|
394
|
+
confirmPassword: string;
|
|
395
|
+
loading: boolean;
|
|
396
|
+
error: string | null;
|
|
397
|
+
message: string | null;
|
|
398
|
+
}
|
|
399
|
+
interface AuthFormActions {
|
|
400
|
+
setEmail: (email: string) => void;
|
|
401
|
+
setPassword: (password: string) => void;
|
|
402
|
+
setConfirmPassword: (password: string) => void;
|
|
403
|
+
handleSignIn: () => Promise<void>;
|
|
404
|
+
handleSignUp: () => Promise<void>;
|
|
405
|
+
handleOAuthSignIn: (provider: OAuthProvider) => Promise<void>;
|
|
406
|
+
handlePasswordReset: () => Promise<void>;
|
|
407
|
+
handleMagicLink: () => Promise<void>;
|
|
408
|
+
clearError: () => void;
|
|
409
|
+
clearMessage: () => void;
|
|
410
|
+
}
|
|
411
|
+
declare const useAuthForm: (options?: UseAuthFormOptions) => AuthFormState & AuthFormActions;
|
|
412
|
+
|
|
413
|
+
interface UseProtectedRouteOptions {
|
|
414
|
+
redirectTo?: string;
|
|
415
|
+
requiredRoles?: string[];
|
|
416
|
+
onUnauthorized?: () => void;
|
|
417
|
+
onUnauthenticated?: () => void;
|
|
418
|
+
}
|
|
419
|
+
declare const useProtectedRoute: (options?: UseProtectedRouteOptions) => {
|
|
420
|
+
user: CommonUser | null | undefined;
|
|
421
|
+
loading: boolean | undefined;
|
|
422
|
+
isAuthenticated: boolean;
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
declare function useRBAC(): {
|
|
426
|
+
checkPermission: (permission: string) => boolean;
|
|
427
|
+
hasRole: (role: string) => boolean;
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
declare function use2FA(): {
|
|
431
|
+
setup2FA: () => Promise<{
|
|
432
|
+
id: string;
|
|
433
|
+
type: "totp";
|
|
434
|
+
totp: {
|
|
435
|
+
qr_code: string;
|
|
436
|
+
secret: string;
|
|
437
|
+
uri: string;
|
|
438
|
+
};
|
|
439
|
+
friendly_name?: string;
|
|
440
|
+
}>;
|
|
441
|
+
verify2FA: (factorId: string, challengeId: string, code: string) => Promise<{
|
|
442
|
+
access_token: string;
|
|
443
|
+
token_type: string;
|
|
444
|
+
expires_in: number;
|
|
445
|
+
refresh_token: string;
|
|
446
|
+
user: _supabase_auth_js.User;
|
|
447
|
+
}>;
|
|
448
|
+
unenroll2FA: (factorId: string) => Promise<{
|
|
449
|
+
id: string;
|
|
450
|
+
}>;
|
|
451
|
+
loading: boolean;
|
|
452
|
+
error: Error | null;
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
declare function useRedirectUrl(defaultUrl?: string): string;
|
|
456
|
+
|
|
457
|
+
declare const AuthContext: react.Context<AuthStore | null>;
|
|
458
|
+
interface AuthProviderProps {
|
|
459
|
+
children: ReactNode;
|
|
460
|
+
providerType?: AuthProviderType;
|
|
461
|
+
storage?: IAuthStorage;
|
|
462
|
+
}
|
|
463
|
+
declare const AuthProvider: ({ children, providerType, storage }: AuthProviderProps) => react_jsx_runtime.JSX.Element;
|
|
464
|
+
|
|
465
|
+
interface AuthStoreProps {
|
|
466
|
+
authProvider: IAuthProvider;
|
|
467
|
+
}
|
|
468
|
+
declare const createAuthStore: ({ authProvider }: AuthStoreProps) => zustand.UseBoundStore<zustand.StoreApi<AuthStore>>;
|
|
469
|
+
|
|
470
|
+
declare const defaultAuthConfig: AuthConfig;
|
|
471
|
+
|
|
472
|
+
declare function validatePassword(password: string, config: AuthConfig['passwordRequirements']): boolean;
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Validation utilities for authentication inputs
|
|
476
|
+
*/
|
|
477
|
+
declare class ValidationUtils {
|
|
478
|
+
/**
|
|
479
|
+
* Validate email address format
|
|
480
|
+
*/
|
|
481
|
+
static validateEmail(email: string): void;
|
|
482
|
+
/**
|
|
483
|
+
* Validate password strength
|
|
484
|
+
*/
|
|
485
|
+
static validatePassword(password: string, requirements?: {
|
|
486
|
+
minLength?: number;
|
|
487
|
+
requireNumbers?: boolean;
|
|
488
|
+
requireSpecialChars?: boolean;
|
|
489
|
+
requireUppercase?: boolean;
|
|
490
|
+
}): void;
|
|
491
|
+
/**
|
|
492
|
+
* Validate OAuth provider
|
|
493
|
+
*/
|
|
494
|
+
static validateOAuthProvider(provider: string): void;
|
|
495
|
+
/**
|
|
496
|
+
* Validate URL format
|
|
497
|
+
*/
|
|
498
|
+
static validateUrl(url: string, fieldName?: string): void;
|
|
499
|
+
/**
|
|
500
|
+
* Validate required string field
|
|
501
|
+
*/
|
|
502
|
+
static validateRequiredString(value: any, fieldName: string): void;
|
|
503
|
+
/**
|
|
504
|
+
* Sanitize email input
|
|
505
|
+
*/
|
|
506
|
+
static sanitizeEmail(email: string): string;
|
|
507
|
+
/**
|
|
508
|
+
* Check if error is a validation error
|
|
509
|
+
*/
|
|
510
|
+
static isValidationError(error: any): error is AuthError;
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Decorator for validating method parameters
|
|
514
|
+
*/
|
|
515
|
+
declare function validateParams(validations: Record<string, (value: any) => void>): (target: any, propertyName: string, descriptor: PropertyDescriptor) => void;
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* Performance optimization utilities for authentication operations
|
|
519
|
+
*/
|
|
520
|
+
/**
|
|
521
|
+
* Simple memoization utility for caching function results
|
|
522
|
+
*/
|
|
523
|
+
declare function memoize<T extends (...args: any[]) => any>(fn: T, keyGenerator?: (...args: Parameters<T>) => string): T;
|
|
524
|
+
/**
|
|
525
|
+
* Debounce utility for rate-limiting function calls
|
|
526
|
+
*/
|
|
527
|
+
declare function debounce<T extends (...args: any[]) => any>(fn: T, delay: number): (...args: Parameters<T>) => void;
|
|
528
|
+
/**
|
|
529
|
+
* Throttle utility for limiting function call frequency
|
|
530
|
+
*/
|
|
531
|
+
declare function throttle<T extends (...args: any[]) => any>(fn: T, limit: number): (...args: Parameters<T>) => void;
|
|
532
|
+
/**
|
|
533
|
+
* Retry utility with exponential backoff
|
|
534
|
+
*/
|
|
535
|
+
declare function retryWithBackoff<T>(fn: () => Promise<T>, maxRetries?: number, baseDelay?: number, maxDelay?: number): Promise<T>;
|
|
536
|
+
/**
|
|
537
|
+
* Simple LRU cache implementation
|
|
538
|
+
*/
|
|
539
|
+
declare class LRUCache<K, V> {
|
|
540
|
+
private cache;
|
|
541
|
+
private maxSize;
|
|
542
|
+
constructor(maxSize?: number);
|
|
543
|
+
get(key: K): V | undefined;
|
|
544
|
+
set(key: K, value: V): void;
|
|
545
|
+
has(key: K): boolean;
|
|
546
|
+
clear(): void;
|
|
547
|
+
size(): number;
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Performance monitoring utility
|
|
551
|
+
*/
|
|
552
|
+
declare class PerformanceMonitor {
|
|
553
|
+
private static timers;
|
|
554
|
+
static start(label: string): void;
|
|
555
|
+
static end(label: string): number;
|
|
556
|
+
static measure<T>(label: string, fn: () => T): T;
|
|
557
|
+
static measureAsync<T>(label: string, fn: () => Promise<T>): Promise<T>;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* Health check result interface
|
|
562
|
+
*/
|
|
563
|
+
interface HealthCheckResult {
|
|
564
|
+
status: 'healthy' | 'warning' | 'error';
|
|
565
|
+
message: string;
|
|
566
|
+
details?: Record<string, any>;
|
|
567
|
+
timestamp: Date;
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* Comprehensive health check results
|
|
571
|
+
*/
|
|
572
|
+
interface SystemHealthCheck {
|
|
573
|
+
overall: 'healthy' | 'warning' | 'error';
|
|
574
|
+
checks: {
|
|
575
|
+
configuration: HealthCheckResult;
|
|
576
|
+
provider: HealthCheckResult;
|
|
577
|
+
storage: HealthCheckResult;
|
|
578
|
+
network?: HealthCheckResult;
|
|
579
|
+
};
|
|
580
|
+
timestamp: Date;
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* Health check utilities for authentication system
|
|
584
|
+
*/
|
|
585
|
+
declare class HealthChecker {
|
|
586
|
+
/**
|
|
587
|
+
* Perform comprehensive system health check
|
|
588
|
+
*/
|
|
589
|
+
static performHealthCheck(): Promise<SystemHealthCheck>;
|
|
590
|
+
/**
|
|
591
|
+
* Check configuration validity
|
|
592
|
+
*/
|
|
593
|
+
static checkConfiguration(): Promise<HealthCheckResult>;
|
|
594
|
+
/**
|
|
595
|
+
* Check provider initialization
|
|
596
|
+
*/
|
|
597
|
+
static checkProvider(): Promise<HealthCheckResult>;
|
|
598
|
+
/**
|
|
599
|
+
* Check storage functionality
|
|
600
|
+
*/
|
|
601
|
+
static checkStorage(): Promise<HealthCheckResult>;
|
|
602
|
+
/**
|
|
603
|
+
* Check network connectivity to authentication services
|
|
604
|
+
*/
|
|
605
|
+
static checkNetworkConnectivity(): Promise<HealthCheckResult>;
|
|
606
|
+
/**
|
|
607
|
+
* Generate health check report
|
|
608
|
+
*/
|
|
609
|
+
static generateReport(healthCheck: SystemHealthCheck): string;
|
|
610
|
+
/**
|
|
611
|
+
* Quick health check for monitoring
|
|
612
|
+
*/
|
|
613
|
+
static quickCheck(): Promise<boolean>;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
declare function withAuth(middleware: (request: NextRequest) => Promise<NextResponse> | NextResponse, options?: {
|
|
617
|
+
publicRoutes?: string[];
|
|
618
|
+
loginRoute?: string;
|
|
619
|
+
}): (req: NextRequest) => Promise<NextResponse<unknown>>;
|
|
620
|
+
|
|
621
|
+
declare function handleEmailVerification(token: string): Promise<{
|
|
622
|
+
success: boolean;
|
|
623
|
+
error?: undefined;
|
|
624
|
+
} | {
|
|
625
|
+
success: boolean;
|
|
626
|
+
error: unknown;
|
|
627
|
+
}>;
|
|
102
628
|
|
|
103
|
-
export { type AuthConfig, type AuthFormProps, type AuthMode, AuthProvider, type AuthState, type AuthStore, type UserRole,
|
|
629
|
+
export { type AuthConfig, AuthContext, AuthError, AuthErrorType, AuthEvent, type AuthFormActions, type AuthFormProps, type AuthFormState, type AuthMode, AuthProvider, type AuthProviderConfig, AuthProviderFactory, type AuthProviderType, type AuthSession, type AuthState, type AuthStore, type CommonUser, FirebaseAuthProvider, type HealthCheckResult, HealthChecker, type IAuthProvider, type IAuthStorage, LRUCache, NativeAuthStorage, type OAuthProvider, PerformanceMonitor, SupabaseAuthProvider, type SystemHealthCheck, type UseAuthFormOptions, type UseProtectedRouteOptions, type UserRole, ValidationUtils, WebAuthStorage, createAuthStorage, createAuthStore, debounce, defaultAuthConfig, handleEmailVerification, memoize, retryWithBackoff, throttle, use2FA, useAuth, useAuthForm, useProtectedRoute, useRBAC, useRedirectUrl, validateParams, validatePassword, withAuth };
|