@chemmangat/msal-next 3.0.1 → 3.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,906 +1,2 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { Configuration, LogLevel, IPublicClientApplication, PublicClientApplication, AccountInfo } from '@azure/msal-browser';
3
- export { AccountInfo } from '@azure/msal-browser';
4
- import { ReactNode, CSSProperties, Component, ErrorInfo, ComponentType } from 'react';
5
- import { NextRequest, NextResponse } from 'next/server';
6
- export { useAccount, useIsAuthenticated, useMsal } from '@azure/msal-react';
7
1
 
8
- /**
9
- * Custom token claims interface for TypeScript generics
10
- * Extend this interface to add your custom claims
11
- *
12
- * @example
13
- * ```tsx
14
- * interface MyCustomClaims extends CustomTokenClaims {
15
- * roles: string[];
16
- * department: string;
17
- * }
18
- *
19
- * const claims = account.idTokenClaims as MyCustomClaims;
20
- * ```
21
- */
22
- interface CustomTokenClaims {
23
- [key: string]: any;
24
- }
25
- interface MsalAuthConfig {
26
- /**
27
- * Azure AD Application (client) ID
28
- */
29
- clientId: string;
30
- /**
31
- * Azure AD Directory (tenant) ID (optional for multi-tenant)
32
- */
33
- tenantId?: string;
34
- /**
35
- * Authority type: 'common' for multi-tenant, 'organizations', 'consumers', or 'tenant' for single-tenant
36
- * @default 'common'
37
- */
38
- authorityType?: 'common' | 'organizations' | 'consumers' | 'tenant';
39
- /**
40
- * Redirect URI after authentication
41
- * @default window.location.origin
42
- */
43
- redirectUri?: string;
44
- /**
45
- * Post logout redirect URI
46
- * @default redirectUri
47
- */
48
- postLogoutRedirectUri?: string;
49
- /**
50
- * Default scopes for authentication
51
- * @default ['User.Read']
52
- */
53
- scopes?: string[];
54
- /**
55
- * Cache location: 'sessionStorage', 'localStorage', or 'memoryStorage'
56
- * @default 'sessionStorage'
57
- */
58
- cacheLocation?: 'sessionStorage' | 'localStorage' | 'memoryStorage';
59
- /**
60
- * Store auth state in cookie (for IE11/Edge legacy)
61
- * @default false
62
- */
63
- storeAuthStateInCookie?: boolean;
64
- /**
65
- * Navigate to login request URL after authentication
66
- * @default true
67
- */
68
- navigateToLoginRequestUrl?: boolean;
69
- /**
70
- * Custom MSAL configuration (overrides all other options)
71
- */
72
- msalConfig?: Configuration;
73
- /**
74
- * Enable debug logging
75
- * @default false
76
- */
77
- enableLogging?: boolean;
78
- /**
79
- * Custom logger callback
80
- */
81
- loggerCallback?: (level: LogLevel, message: string, containsPii: boolean) => void;
82
- /**
83
- * Allowed redirect URIs for validation (optional but recommended)
84
- * Helps prevent open redirect vulnerabilities
85
- * @example ['https://myapp.com', 'http://localhost:3000']
86
- */
87
- allowedRedirectUris?: string[];
88
- /**
89
- * Loading component to show while MSAL initializes
90
- */
91
- loadingComponent?: ReactNode;
92
- /**
93
- * Callback invoked after MSAL initialization completes successfully
94
- */
95
- onInitialized?: (instance: IPublicClientApplication) => void;
96
- }
97
- interface MsalAuthProviderProps extends MsalAuthConfig {
98
- children: ReactNode;
99
- }
100
-
101
- /**
102
- * Get the current MSAL instance
103
- * @returns The MSAL instance or null if not initialized
104
- */
105
- declare function getMsalInstance(): PublicClientApplication | null;
106
- declare function MsalAuthProvider({ children, loadingComponent, onInitialized, ...config }: MsalAuthProviderProps): react_jsx_runtime.JSX.Element;
107
-
108
- interface MicrosoftSignInButtonProps {
109
- /**
110
- * Button text
111
- * @default 'Sign in with Microsoft'
112
- */
113
- text?: string;
114
- /**
115
- * Button variant
116
- * @default 'dark'
117
- */
118
- variant?: 'dark' | 'light';
119
- /**
120
- * Button size
121
- * @default 'medium'
122
- */
123
- size?: 'small' | 'medium' | 'large';
124
- /**
125
- * Use redirect flow instead of popup
126
- * @default false
127
- */
128
- useRedirect?: boolean;
129
- /**
130
- * Scopes to request
131
- */
132
- scopes?: string[];
133
- /**
134
- * Custom className
135
- */
136
- className?: string;
137
- /**
138
- * Custom styles
139
- */
140
- style?: CSSProperties;
141
- /**
142
- * Callback on successful login
143
- */
144
- onSuccess?: () => void;
145
- /**
146
- * Callback on error
147
- */
148
- onError?: (error: Error) => void;
149
- }
150
- declare function MicrosoftSignInButton({ text, variant, size, useRedirect, scopes, className, style, onSuccess, onError, }: MicrosoftSignInButtonProps): react_jsx_runtime.JSX.Element;
151
-
152
- interface SignOutButtonProps {
153
- /**
154
- * Button text
155
- * @default 'Sign out'
156
- */
157
- text?: string;
158
- /**
159
- * Button variant
160
- * @default 'dark'
161
- */
162
- variant?: 'dark' | 'light';
163
- /**
164
- * Button size
165
- * @default 'medium'
166
- */
167
- size?: 'small' | 'medium' | 'large';
168
- /**
169
- * Use redirect flow instead of popup
170
- * @default false
171
- */
172
- useRedirect?: boolean;
173
- /**
174
- * Custom className
175
- */
176
- className?: string;
177
- /**
178
- * Custom styles
179
- */
180
- style?: CSSProperties;
181
- /**
182
- * Callback on successful logout
183
- */
184
- onSuccess?: () => void;
185
- /**
186
- * Callback on error
187
- */
188
- onError?: (error: Error) => void;
189
- }
190
- /**
191
- * SignOutButton component with Microsoft branding
192
- *
193
- * @example
194
- * ```tsx
195
- * <SignOutButton variant="light" />
196
- * ```
197
- */
198
- declare function SignOutButton({ text, variant, size, useRedirect, className, style, onSuccess, onError, }: SignOutButtonProps): react_jsx_runtime.JSX.Element;
199
-
200
- interface UserAvatarProps {
201
- /**
202
- * Avatar size in pixels
203
- * @default 40
204
- */
205
- size?: number;
206
- /**
207
- * Custom className
208
- */
209
- className?: string;
210
- /**
211
- * Custom styles
212
- */
213
- style?: CSSProperties;
214
- /**
215
- * Show user name tooltip on hover
216
- * @default true
217
- */
218
- showTooltip?: boolean;
219
- /**
220
- * Fallback image URL if MS Graph photo fails
221
- */
222
- fallbackImage?: string;
223
- }
224
- /**
225
- * UserAvatar component that displays user photo from MS Graph with fallback initials
226
- *
227
- * @example
228
- * ```tsx
229
- * <UserAvatar size={48} />
230
- * ```
231
- */
232
- declare function UserAvatar({ size, className, style, showTooltip, fallbackImage, }: UserAvatarProps): react_jsx_runtime.JSX.Element;
233
-
234
- interface AuthStatusProps {
235
- /**
236
- * Custom className
237
- */
238
- className?: string;
239
- /**
240
- * Custom styles
241
- */
242
- style?: CSSProperties;
243
- /**
244
- * Show detailed status (includes username)
245
- * @default false
246
- */
247
- showDetails?: boolean;
248
- /**
249
- * Custom render function for loading state
250
- */
251
- renderLoading?: () => ReactNode;
252
- /**
253
- * Custom render function for authenticated state
254
- */
255
- renderAuthenticated?: (username: string) => ReactNode;
256
- /**
257
- * Custom render function for unauthenticated state
258
- */
259
- renderUnauthenticated?: () => ReactNode;
260
- }
261
- /**
262
- * AuthStatus component that shows current authentication state
263
- *
264
- * @example
265
- * ```tsx
266
- * <AuthStatus showDetails />
267
- * ```
268
- */
269
- declare function AuthStatus({ className, style, showDetails, renderLoading, renderAuthenticated, renderUnauthenticated, }: AuthStatusProps): react_jsx_runtime.JSX.Element;
270
-
271
- interface AuthGuardProps {
272
- /**
273
- * Content to render when authenticated
274
- */
275
- children: ReactNode;
276
- /**
277
- * Component to show while checking authentication
278
- */
279
- loadingComponent?: ReactNode;
280
- /**
281
- * Component to show when not authenticated (before redirect)
282
- */
283
- fallbackComponent?: ReactNode;
284
- /**
285
- * Use redirect flow instead of popup
286
- * @default true
287
- */
288
- useRedirect?: boolean;
289
- /**
290
- * Scopes to request during authentication
291
- */
292
- scopes?: string[];
293
- /**
294
- * Callback when authentication is required
295
- */
296
- onAuthRequired?: () => void;
297
- }
298
- /**
299
- * AuthGuard component that protects content and auto-redirects to login
300
- *
301
- * @example
302
- * ```tsx
303
- * <AuthGuard>
304
- * <ProtectedContent />
305
- * </AuthGuard>
306
- * ```
307
- */
308
- declare function AuthGuard({ children, loadingComponent, fallbackComponent, useRedirect, scopes, onAuthRequired, }: AuthGuardProps): react_jsx_runtime.JSX.Element;
309
-
310
- interface ErrorBoundaryProps {
311
- /**
312
- * Content to render when no error
313
- */
314
- children: ReactNode;
315
- /**
316
- * Custom error fallback component
317
- */
318
- fallback?: (error: Error, reset: () => void) => ReactNode;
319
- /**
320
- * Callback when error occurs
321
- */
322
- onError?: (error: Error, errorInfo: ErrorInfo) => void;
323
- /**
324
- * Enable debug logging
325
- * @default false
326
- */
327
- debug?: boolean;
328
- }
329
- interface ErrorBoundaryState {
330
- hasError: boolean;
331
- error: Error | null;
332
- }
333
- /**
334
- * Error boundary for catching authentication errors
335
- *
336
- * @example
337
- * ```tsx
338
- * <ErrorBoundary>
339
- * <MsalAuthProvider clientId="...">
340
- * <App />
341
- * </MsalAuthProvider>
342
- * </ErrorBoundary>
343
- * ```
344
- */
345
- declare class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
346
- constructor(props: ErrorBoundaryProps);
347
- static getDerivedStateFromError(error: Error): ErrorBoundaryState;
348
- componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
349
- reset: () => void;
350
- render(): ReactNode;
351
- }
352
-
353
- interface UseMsalAuthReturn {
354
- /**
355
- * Current authenticated account
356
- */
357
- account: AccountInfo | null;
358
- /**
359
- * All accounts in the cache
360
- */
361
- accounts: AccountInfo[];
362
- /**
363
- * Whether user is authenticated
364
- */
365
- isAuthenticated: boolean;
366
- /**
367
- * Whether MSAL is currently performing an interaction
368
- */
369
- inProgress: boolean;
370
- /**
371
- * Login using popup
372
- */
373
- loginPopup: (scopes?: string[]) => Promise<void>;
374
- /**
375
- * Login using redirect
376
- */
377
- loginRedirect: (scopes?: string[]) => Promise<void>;
378
- /**
379
- * Logout using popup
380
- */
381
- logoutPopup: () => Promise<void>;
382
- /**
383
- * Logout using redirect
384
- */
385
- logoutRedirect: () => Promise<void>;
386
- /**
387
- * Acquire access token silently (with fallback to popup)
388
- */
389
- acquireToken: (scopes: string[]) => Promise<string>;
390
- /**
391
- * Acquire access token silently only (no fallback)
392
- */
393
- acquireTokenSilent: (scopes: string[]) => Promise<string>;
394
- /**
395
- * Acquire access token using popup
396
- */
397
- acquireTokenPopup: (scopes: string[]) => Promise<string>;
398
- /**
399
- * Acquire access token using redirect
400
- */
401
- acquireTokenRedirect: (scopes: string[]) => Promise<void>;
402
- /**
403
- * Clear MSAL session without triggering Microsoft logout
404
- */
405
- clearSession: () => Promise<void>;
406
- }
407
- declare function useMsalAuth(defaultScopes?: string[]): UseMsalAuthReturn;
408
-
409
- interface GraphApiOptions extends RequestInit {
410
- /**
411
- * Scopes required for the API call
412
- * @default ['User.Read']
413
- */
414
- scopes?: string[];
415
- /**
416
- * API version
417
- * @default 'v1.0'
418
- */
419
- version?: 'v1.0' | 'beta';
420
- /**
421
- * Enable debug logging
422
- * @default false
423
- */
424
- debug?: boolean;
425
- }
426
- interface UseGraphApiReturn {
427
- /**
428
- * Make a GET request to MS Graph API
429
- */
430
- get: <T = any>(endpoint: string, options?: GraphApiOptions) => Promise<T>;
431
- /**
432
- * Make a POST request to MS Graph API
433
- */
434
- post: <T = any>(endpoint: string, body?: any, options?: GraphApiOptions) => Promise<T>;
435
- /**
436
- * Make a PUT request to MS Graph API
437
- */
438
- put: <T = any>(endpoint: string, body?: any, options?: GraphApiOptions) => Promise<T>;
439
- /**
440
- * Make a PATCH request to MS Graph API
441
- */
442
- patch: <T = any>(endpoint: string, body?: any, options?: GraphApiOptions) => Promise<T>;
443
- /**
444
- * Make a DELETE request to MS Graph API
445
- */
446
- delete: <T = any>(endpoint: string, options?: GraphApiOptions) => Promise<T>;
447
- /**
448
- * Make a custom request to MS Graph API
449
- */
450
- request: <T = any>(endpoint: string, options?: GraphApiOptions) => Promise<T>;
451
- }
452
- /**
453
- * Hook for making authenticated requests to MS Graph API
454
- *
455
- * @example
456
- * ```tsx
457
- * const graph = useGraphApi();
458
- * const user = await graph.get('/me');
459
- * ```
460
- */
461
- declare function useGraphApi(): UseGraphApiReturn;
462
-
463
- interface UserProfile {
464
- id: string;
465
- displayName: string;
466
- givenName: string;
467
- surname: string;
468
- userPrincipalName: string;
469
- mail: string;
470
- jobTitle?: string;
471
- officeLocation?: string;
472
- mobilePhone?: string;
473
- businessPhones?: string[];
474
- photo?: string;
475
- }
476
- interface UseUserProfileReturn {
477
- /**
478
- * User profile data
479
- */
480
- profile: UserProfile | null;
481
- /**
482
- * Whether profile is loading
483
- */
484
- loading: boolean;
485
- /**
486
- * Error if profile fetch failed
487
- */
488
- error: Error | null;
489
- /**
490
- * Refetch user profile
491
- */
492
- refetch: () => Promise<void>;
493
- /**
494
- * Clear cached profile
495
- */
496
- clearCache: () => void;
497
- }
498
- /**
499
- * Hook for fetching and caching user profile from MS Graph
500
- *
501
- * @example
502
- * ```tsx
503
- * const { profile, loading } = useUserProfile();
504
- * ```
505
- */
506
- declare function useUserProfile(): UseUserProfileReturn;
507
-
508
- interface UseRolesReturn {
509
- /**
510
- * User's Azure AD roles
511
- */
512
- roles: string[];
513
- /**
514
- * User's Azure AD groups
515
- */
516
- groups: string[];
517
- /**
518
- * Whether roles/groups are loading
519
- */
520
- loading: boolean;
521
- /**
522
- * Error if fetch failed
523
- */
524
- error: Error | null;
525
- /**
526
- * Check if user has a specific role
527
- */
528
- hasRole: (role: string) => boolean;
529
- /**
530
- * Check if user is in a specific group
531
- */
532
- hasGroup: (groupId: string) => boolean;
533
- /**
534
- * Check if user has any of the specified roles
535
- */
536
- hasAnyRole: (roles: string[]) => boolean;
537
- /**
538
- * Check if user has all of the specified roles
539
- */
540
- hasAllRoles: (roles: string[]) => boolean;
541
- /**
542
- * Refetch roles and groups
543
- */
544
- refetch: () => Promise<void>;
545
- }
546
- /**
547
- * Hook for fetching user's Azure AD roles and groups
548
- *
549
- * @example
550
- * ```tsx
551
- * const { roles, hasRole } = useRoles();
552
- * if (hasRole('Admin')) {
553
- * // Show admin content
554
- * }
555
- * ```
556
- */
557
- declare function useRoles(): UseRolesReturn;
558
-
559
- declare function createMsalConfig(config: MsalAuthConfig): Configuration;
560
-
561
- interface WithAuthOptions extends Omit<AuthGuardProps, 'children'> {
562
- /**
563
- * Display name for the wrapped component (for debugging)
564
- */
565
- displayName?: string;
566
- }
567
- /**
568
- * Higher-order component for protecting pages/components
569
- *
570
- * @example
571
- * ```tsx
572
- * const ProtectedPage = withAuth(MyPage);
573
- *
574
- * // With options
575
- * const ProtectedPage = withAuth(MyPage, {
576
- * useRedirect: true,
577
- * scopes: ['User.Read', 'Mail.Read']
578
- * });
579
- * ```
580
- */
581
- declare function withAuth<P extends object>(Component: ComponentType<P>, options?: WithAuthOptions): ComponentType<P>;
582
-
583
- /**
584
- * Retry configuration for token acquisition
585
- */
586
- interface RetryConfig {
587
- /**
588
- * Maximum number of retry attempts
589
- * @default 3
590
- */
591
- maxRetries?: number;
592
- /**
593
- * Initial delay in milliseconds
594
- * @default 1000
595
- */
596
- initialDelay?: number;
597
- /**
598
- * Maximum delay in milliseconds
599
- * @default 10000
600
- */
601
- maxDelay?: number;
602
- /**
603
- * Backoff multiplier
604
- * @default 2
605
- */
606
- backoffMultiplier?: number;
607
- /**
608
- * Enable debug logging
609
- * @default false
610
- */
611
- debug?: boolean;
612
- }
613
- /**
614
- * Exponential backoff retry utility for token acquisition
615
- *
616
- * @example
617
- * ```tsx
618
- * const token = await retryWithBackoff(
619
- * () => acquireTokenSilent(scopes),
620
- * { maxRetries: 3, debug: true }
621
- * );
622
- * ```
623
- */
624
- declare function retryWithBackoff<T>(fn: () => Promise<T>, config?: RetryConfig): Promise<T>;
625
- /**
626
- * Create a retry wrapper for a function
627
- *
628
- * @example
629
- * ```tsx
630
- * const acquireTokenWithRetry = createRetryWrapper(acquireToken, {
631
- * maxRetries: 3,
632
- * debug: true
633
- * });
634
- *
635
- * const token = await acquireTokenWithRetry(scopes);
636
- * ```
637
- */
638
- declare function createRetryWrapper<TArgs extends any[], TReturn>(fn: (...args: TArgs) => Promise<TReturn>, config?: RetryConfig): (...args: TArgs) => Promise<TReturn>;
639
-
640
- /**
641
- * Debug logger configuration
642
- */
643
- interface DebugLoggerConfig {
644
- /**
645
- * Enable debug mode
646
- * @default false
647
- */
648
- enabled?: boolean;
649
- /**
650
- * Prefix for log messages
651
- * @default '[MSAL-Next]'
652
- */
653
- prefix?: string;
654
- /**
655
- * Show timestamps
656
- * @default true
657
- */
658
- showTimestamp?: boolean;
659
- /**
660
- * Log level
661
- * @default 'info'
662
- */
663
- level?: 'error' | 'warn' | 'info' | 'debug';
664
- /**
665
- * Enable performance tracking
666
- * @default false
667
- */
668
- enablePerformance?: boolean;
669
- /**
670
- * Enable network request logging
671
- * @default false
672
- */
673
- enableNetworkLogs?: boolean;
674
- /**
675
- * Maximum log history size
676
- * @default 100
677
- */
678
- maxHistorySize?: number;
679
- }
680
- /**
681
- * Log entry for history tracking
682
- */
683
- interface LogEntry {
684
- timestamp: number;
685
- level: string;
686
- message: string;
687
- data?: any;
688
- }
689
- /**
690
- * Performance timing entry
691
- */
692
- interface PerformanceTiming {
693
- operation: string;
694
- startTime: number;
695
- endTime?: number;
696
- duration?: number;
697
- }
698
- declare class DebugLogger {
699
- private config;
700
- private logHistory;
701
- private performanceTimings;
702
- constructor(config?: DebugLoggerConfig);
703
- private shouldLog;
704
- private formatMessage;
705
- private addToHistory;
706
- error(message: string, data?: any): void;
707
- warn(message: string, data?: any): void;
708
- info(message: string, data?: any): void;
709
- debug(message: string, data?: any): void;
710
- group(label: string): void;
711
- groupEnd(): void;
712
- /**
713
- * Start performance timing for an operation
714
- */
715
- startTiming(operation: string): void;
716
- /**
717
- * End performance timing for an operation
718
- */
719
- endTiming(operation: string): number | undefined;
720
- /**
721
- * Log network request
722
- */
723
- logRequest(method: string, url: string, options?: any): void;
724
- /**
725
- * Log network response
726
- */
727
- logResponse(method: string, url: string, status: number, data?: any): void;
728
- /**
729
- * Get log history
730
- */
731
- getHistory(): LogEntry[];
732
- /**
733
- * Get performance timings
734
- */
735
- getPerformanceTimings(): PerformanceTiming[];
736
- /**
737
- * Clear log history
738
- */
739
- clearHistory(): void;
740
- /**
741
- * Clear performance timings
742
- */
743
- clearTimings(): void;
744
- /**
745
- * Export logs as JSON
746
- */
747
- exportLogs(): string;
748
- /**
749
- * Download logs as a file
750
- */
751
- downloadLogs(filename?: string): void;
752
- setEnabled(enabled: boolean): void;
753
- setLevel(level: DebugLoggerConfig['level']): void;
754
- }
755
- /**
756
- * Get or create the global debug logger
757
- *
758
- * @example
759
- * ```tsx
760
- * const logger = getDebugLogger({
761
- * enabled: true,
762
- * level: 'debug',
763
- * enablePerformance: true,
764
- * enableNetworkLogs: true
765
- * });
766
- *
767
- * logger.startTiming('token-acquisition');
768
- * // ... do work
769
- * logger.endTiming('token-acquisition');
770
- *
771
- * logger.logRequest('GET', '/me');
772
- * logger.info('User logged in', { username: 'user@example.com' });
773
- *
774
- * // Export logs for debugging
775
- * logger.downloadLogs();
776
- * ```
777
- */
778
- declare function getDebugLogger(config?: DebugLoggerConfig): DebugLogger;
779
- /**
780
- * Create a scoped logger with a custom prefix
781
- *
782
- * @example
783
- * ```tsx
784
- * const logger = createScopedLogger('GraphAPI', {
785
- * enabled: true,
786
- * enableNetworkLogs: true
787
- * });
788
- * logger.info('Fetching user profile');
789
- * ```
790
- */
791
- declare function createScopedLogger(scope: string, config?: DebugLoggerConfig): DebugLogger;
792
-
793
- /**
794
- * Security utilities for input validation and sanitization
795
- */
796
- /**
797
- * Validate account data structure from cookie
798
- */
799
- interface ValidatedAccountData {
800
- homeAccountId: string;
801
- username: string;
802
- name?: string;
803
- }
804
- /**
805
- * Safely parse and validate JSON from untrusted sources
806
- */
807
- declare function safeJsonParse<T>(jsonString: string, validator: (data: any) => data is T): T | null;
808
- /**
809
- * Validate account data structure
810
- */
811
- declare function isValidAccountData(data: any): data is ValidatedAccountData;
812
- /**
813
- * Sanitize error messages to prevent information disclosure
814
- */
815
- declare function sanitizeError(error: unknown): string;
816
- /**
817
- * Validate redirect URI to prevent open redirect vulnerabilities
818
- */
819
- declare function isValidRedirectUri(uri: string, allowedOrigins: string[]): boolean;
820
- /**
821
- * Validate scope strings to prevent injection
822
- */
823
- declare function isValidScope(scope: string): boolean;
824
- /**
825
- * Validate array of scopes
826
- */
827
- declare function validateScopes(scopes: string[]): boolean;
828
-
829
- interface AuthMiddlewareConfig {
830
- /**
831
- * Routes that require authentication
832
- * @example ['/dashboard', '/profile', '/api/protected']
833
- */
834
- protectedRoutes?: string[];
835
- /**
836
- * Routes that should be accessible only when NOT authenticated
837
- * @example ['/login', '/signup']
838
- */
839
- publicOnlyRoutes?: string[];
840
- /**
841
- * Login page path
842
- * @default '/login'
843
- */
844
- loginPath?: string;
845
- /**
846
- * Redirect path after login
847
- * @default '/'
848
- */
849
- redirectAfterLogin?: string;
850
- /**
851
- * Cookie name for session
852
- * @default 'msal.account'
853
- */
854
- sessionCookie?: string;
855
- /**
856
- * Custom authentication check function
857
- */
858
- isAuthenticated?: (request: NextRequest) => boolean | Promise<boolean>;
859
- /**
860
- * Enable debug logging
861
- * @default false
862
- */
863
- debug?: boolean;
864
- }
865
- /**
866
- * Creates authentication middleware for Next.js App Router
867
- *
868
- * @example
869
- * ```tsx
870
- * // middleware.ts
871
- * import { createAuthMiddleware } from '@chemmangat/msal-next';
872
- *
873
- * export const middleware = createAuthMiddleware({
874
- * protectedRoutes: ['/dashboard', '/profile'],
875
- * publicOnlyRoutes: ['/login'],
876
- * loginPath: '/login',
877
- * });
878
- *
879
- * export const config = {
880
- * matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
881
- * };
882
- * ```
883
- */
884
- declare function createAuthMiddleware(config?: AuthMiddlewareConfig): (request: NextRequest) => Promise<NextResponse<unknown>>;
885
-
886
- interface ServerSession {
887
- /**
888
- * Whether user is authenticated
889
- */
890
- isAuthenticated: boolean;
891
- /**
892
- * User's account ID from MSAL cache
893
- */
894
- accountId?: string;
895
- /**
896
- * User's username/email
897
- */
898
- username?: string;
899
- /**
900
- * Access token (if available in cookie)
901
- * @deprecated Storing tokens in cookies is not recommended for security reasons
902
- */
903
- accessToken?: string;
904
- }
905
-
906
- export { AuthGuard, type AuthGuardProps, type AuthMiddlewareConfig, AuthStatus, type AuthStatusProps, type CustomTokenClaims, type DebugLoggerConfig, ErrorBoundary, type ErrorBoundaryProps, type GraphApiOptions, MicrosoftSignInButton, type MicrosoftSignInButtonProps, type MsalAuthConfig, MsalAuthProvider, type MsalAuthProviderProps, type RetryConfig, type ServerSession, SignOutButton, type SignOutButtonProps, type UseGraphApiReturn, type UseMsalAuthReturn, type UseRolesReturn, type UseUserProfileReturn, UserAvatar, type UserAvatarProps, type UserProfile, type ValidatedAccountData, type WithAuthOptions, createAuthMiddleware, createMsalConfig, createRetryWrapper, createScopedLogger, getDebugLogger, getMsalInstance, isValidAccountData, isValidRedirectUri, isValidScope, retryWithBackoff, safeJsonParse, sanitizeError, useGraphApi, useMsalAuth, useRoles, useUserProfile, validateScopes, withAuth };
2
+ export { }