@abaxx_tech/v-integration-react 1.2.0-dev.7 → 1.2.0-dev.8
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 +329 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -257,21 +257,21 @@ Email input authentication component only. Provides a standalone email/Abaxx ID
|
|
|
257
257
|
|
|
258
258
|
## Error Handling
|
|
259
259
|
|
|
260
|
+
The library provides comprehensive error handling through two mechanisms: React Error Boundary for component errors and `authError` in the context for authentication flow errors.
|
|
261
|
+
|
|
260
262
|
### React Error Boundary
|
|
261
263
|
|
|
262
264
|
All authentication components (`VerifierAuth`, `VerifierAuthQr`, and `VerifierAuthEmail`) are automatically wrapped with an `AuthErrorBoundary` component that catches React errors during rendering or in lifecycle methods.
|
|
263
265
|
|
|
264
266
|
#### Features:
|
|
265
267
|
- **Automatic Error Catching**: Catches errors that occur in the component tree during rendering
|
|
266
|
-
- **User-Friendly Error UI**: Displays a centered error message with a
|
|
267
|
-
- **Error Recovery**: Provides a "Try Again" button to reset the error state and retry
|
|
268
|
+
- **User-Friendly Error UI**: Displays a centered error message with a fixed overlay background
|
|
268
269
|
- **Error Logging**: Automatically logs errors to the console for debugging
|
|
269
270
|
|
|
270
271
|
#### Error Display:
|
|
271
|
-
When
|
|
272
|
+
When a React error occurs, users will see:
|
|
272
273
|
- A centered error message: "Something went wrong"
|
|
273
|
-
- A descriptive message: "An unexpected error occurred
|
|
274
|
-
- A "Try Again" button to reset the error state
|
|
274
|
+
- A descriptive message: "An unexpected error occurred. Please try again later."
|
|
275
275
|
|
|
276
276
|
The error boundary uses a fixed position overlay that covers the entire viewport, ensuring the error message is always visible and centered both vertically and horizontally.
|
|
277
277
|
|
|
@@ -287,7 +287,330 @@ const LoginPage = () => {
|
|
|
287
287
|
};
|
|
288
288
|
```
|
|
289
289
|
|
|
290
|
-
**Note**: The error boundary only catches errors in React components. For network errors or
|
|
290
|
+
**Note**: The error boundary only catches errors in React components. For network errors, API errors, or authentication flow errors, use the `authError` property from `VContext` to handle them in your application logic.
|
|
291
|
+
|
|
292
|
+
### Authentication Error States (`authError`)
|
|
293
|
+
|
|
294
|
+
The `authError` property in `VContext` contains error messages for authentication flow failures. All error states are documented below with their causes, recovery strategies, and handling examples.
|
|
295
|
+
|
|
296
|
+
#### Error Categories
|
|
297
|
+
|
|
298
|
+
##### 1. Input Validation Errors
|
|
299
|
+
|
|
300
|
+
These errors occur when user input is invalid or missing.
|
|
301
|
+
|
|
302
|
+
| Error Message | Cause | When It Occurs |
|
|
303
|
+
|--------------|-------|----------------|
|
|
304
|
+
| `"Invalid login. Email or Abaxx ID is required."` | Empty alias field | User attempts to authenticate without entering email/Abaxx ID |
|
|
305
|
+
| `"Invalid login. Please use your existing Email or Abaxx ID."` | Invalid or non-existent alias | Server responds with "Unable to request auth." |
|
|
306
|
+
|
|
307
|
+
**Recovery Strategy:**
|
|
308
|
+
- Clear the error message
|
|
309
|
+
- Allow user to re-enter their email/Abaxx ID
|
|
310
|
+
- Provide helpful validation feedback before submission
|
|
311
|
+
- No need to reset the entire authentication state
|
|
312
|
+
|
|
313
|
+
**Example:**
|
|
314
|
+
```tsx
|
|
315
|
+
import { useContext, useEffect } from 'react';
|
|
316
|
+
import { VContext } from "@abaxx_tech/v-integration-react";
|
|
317
|
+
|
|
318
|
+
const LoginForm = () => {
|
|
319
|
+
const { authError, setAuthError } = useContext(VContext);
|
|
320
|
+
|
|
321
|
+
useEffect(() => {
|
|
322
|
+
if (authError?.includes("Invalid login")) {
|
|
323
|
+
// Clear error when user starts typing
|
|
324
|
+
const timer = setTimeout(() => setAuthError(null), 5000);
|
|
325
|
+
return () => clearTimeout(timer);
|
|
326
|
+
}
|
|
327
|
+
}, [authError, setAuthError]);
|
|
328
|
+
|
|
329
|
+
return (
|
|
330
|
+
<div>
|
|
331
|
+
{authError && (
|
|
332
|
+
<div className="error-message">
|
|
333
|
+
{authError}
|
|
334
|
+
<button onClick={() => setAuthError(null)}>Dismiss</button>
|
|
335
|
+
</div>
|
|
336
|
+
)}
|
|
337
|
+
{/* Your login form */}
|
|
338
|
+
</div>
|
|
339
|
+
);
|
|
340
|
+
};
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
##### 2. Authentication Request Errors
|
|
344
|
+
|
|
345
|
+
These errors occur when the authentication request to the server fails.
|
|
346
|
+
|
|
347
|
+
| Error Message | Cause | When It Occurs |
|
|
348
|
+
|--------------|-------|----------------|
|
|
349
|
+
| `"Auth request failed: ${message}"` | Server rejected the request | HTTP response is not OK or `data.ok === false` |
|
|
350
|
+
| `"Auth request failed: ${error}"` | Network or fetch exception | Exception thrown during fetch request |
|
|
351
|
+
| `"Something went wrong. Please try again later."` | Unexpected error | Generic catch-all error in authentication flow |
|
|
352
|
+
|
|
353
|
+
**Recovery Strategy:**
|
|
354
|
+
- For network errors: Retry the request after a short delay
|
|
355
|
+
- For server errors: Check API configuration and server status
|
|
356
|
+
- Provide a "Retry" button to allow manual retry
|
|
357
|
+
- Consider resetting authentication state if multiple retries fail
|
|
358
|
+
|
|
359
|
+
**Example:**
|
|
360
|
+
```tsx
|
|
361
|
+
import { useContext, useState } from 'react';
|
|
362
|
+
import { VContext, useVerifierReset } from "@abaxx_tech/v-integration-react";
|
|
363
|
+
|
|
364
|
+
const ErrorHandler = () => {
|
|
365
|
+
const { authError, setAuthError } = useContext(VContext);
|
|
366
|
+
const resetState = useVerifierReset();
|
|
367
|
+
const [retryCount, setRetryCount] = useState(0);
|
|
368
|
+
|
|
369
|
+
const handleRetry = () => {
|
|
370
|
+
setAuthError(null);
|
|
371
|
+
setRetryCount(prev => prev + 1);
|
|
372
|
+
// Trigger re-authentication
|
|
373
|
+
window.location.reload(); // Or use your retry logic
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
const handleReset = () => {
|
|
377
|
+
resetState();
|
|
378
|
+
setRetryCount(0);
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
if (!authError) return null;
|
|
382
|
+
|
|
383
|
+
const isNetworkError = authError.includes("Auth request failed");
|
|
384
|
+
const isGenericError = authError.includes("Something went wrong");
|
|
385
|
+
|
|
386
|
+
return (
|
|
387
|
+
<div className="error-container">
|
|
388
|
+
<div className="error-message">{authError}</div>
|
|
389
|
+
{isNetworkError && retryCount < 3 && (
|
|
390
|
+
<button onClick={handleRetry}>
|
|
391
|
+
Retry ({retryCount}/3)
|
|
392
|
+
</button>
|
|
393
|
+
)}
|
|
394
|
+
<button onClick={handleReset}>
|
|
395
|
+
Start Over
|
|
396
|
+
</button>
|
|
397
|
+
</div>
|
|
398
|
+
);
|
|
399
|
+
};
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
##### 3. SSE Connection Errors
|
|
403
|
+
|
|
404
|
+
These errors occur when the Server-Sent Events (SSE) connection fails or is interrupted.
|
|
405
|
+
|
|
406
|
+
| Error Message | Cause | When It Occurs |
|
|
407
|
+
|--------------|-------|----------------|
|
|
408
|
+
| `"Connection lost. Reconnecting... (attempt X/3)"` | SSE connection interrupted | Connection lost during authentication flow (automatic retry in progress) |
|
|
409
|
+
| `"Unable to establish connection. Please check your network and try again."` | Maximum retries exceeded | SSE connection failed after 3 retry attempts |
|
|
410
|
+
| `"Connection setup failed: ${error}"` | SSE initialization failure | Failed to create EventSource connection |
|
|
411
|
+
|
|
412
|
+
**Recovery Strategy:**
|
|
413
|
+
- For reconnection errors: Wait for automatic retry (library handles this)
|
|
414
|
+
- For connection failures: Check network connectivity and API URL configuration
|
|
415
|
+
- Provide user feedback about connection status
|
|
416
|
+
- Allow manual retry by resetting state and restarting authentication
|
|
417
|
+
- Consider implementing exponential backoff for manual retries
|
|
418
|
+
|
|
419
|
+
**Example:**
|
|
420
|
+
```tsx
|
|
421
|
+
import { useContext, useEffect } from 'react';
|
|
422
|
+
import { VContext, useVerifierReset } from "@abaxx_tech/v-integration-react";
|
|
423
|
+
|
|
424
|
+
const ConnectionStatus = () => {
|
|
425
|
+
const { authError, setAuthError } = useContext(VContext);
|
|
426
|
+
const resetState = useVerifierReset();
|
|
427
|
+
|
|
428
|
+
useEffect(() => {
|
|
429
|
+
if (authError?.includes("Connection lost")) {
|
|
430
|
+
// Connection is being retried automatically
|
|
431
|
+
// Just show status, no action needed
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
if (authError?.includes("Unable to establish connection")) {
|
|
436
|
+
// Maximum retries exceeded
|
|
437
|
+
// User should manually retry
|
|
438
|
+
}
|
|
439
|
+
}, [authError]);
|
|
440
|
+
|
|
441
|
+
const handleManualRetry = () => {
|
|
442
|
+
resetState();
|
|
443
|
+
setAuthError(null);
|
|
444
|
+
// State reset will trigger new SSE connection
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
if (!authError) return null;
|
|
448
|
+
|
|
449
|
+
const isReconnecting = authError.includes("Reconnecting");
|
|
450
|
+
const isConnectionFailed = authError.includes("Unable to establish");
|
|
451
|
+
|
|
452
|
+
return (
|
|
453
|
+
<div className="connection-status">
|
|
454
|
+
{isReconnecting && (
|
|
455
|
+
<div className="reconnecting">
|
|
456
|
+
<Spinner />
|
|
457
|
+
<span>{authError}</span>
|
|
458
|
+
</div>
|
|
459
|
+
)}
|
|
460
|
+
{isConnectionFailed && (
|
|
461
|
+
<div className="connection-failed">
|
|
462
|
+
<p>{authError}</p>
|
|
463
|
+
<button onClick={handleManualRetry}>
|
|
464
|
+
Try Again
|
|
465
|
+
</button>
|
|
466
|
+
</div>
|
|
467
|
+
)}
|
|
468
|
+
</div>
|
|
469
|
+
);
|
|
470
|
+
};
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
##### 4. Token Exchange Errors
|
|
474
|
+
|
|
475
|
+
These errors occur when exchanging the authorization code for an access token fails.
|
|
476
|
+
|
|
477
|
+
| Error Message | Cause | When It Occurs |
|
|
478
|
+
|--------------|-------|----------------|
|
|
479
|
+
| `"Failed to obtain auth token: ${error}"` | Token exchange failed | Server rejected token exchange request or network error occurred |
|
|
480
|
+
|
|
481
|
+
**Recovery Strategy:**
|
|
482
|
+
- This is a critical error - authentication cannot complete
|
|
483
|
+
- Reset authentication state to start fresh
|
|
484
|
+
- Check server logs and API configuration
|
|
485
|
+
- Verify PKCE code verifier is correctly generated
|
|
486
|
+
- Consider logging this error for debugging
|
|
487
|
+
|
|
488
|
+
**Example:**
|
|
489
|
+
```tsx
|
|
490
|
+
import { useContext, useEffect } from 'react';
|
|
491
|
+
import { VContext, useVerifierReset } from "@abaxx_tech/v-integration-react";
|
|
492
|
+
|
|
493
|
+
const TokenErrorHandler = () => {
|
|
494
|
+
const { authError, setAuthError } = useContext(VContext);
|
|
495
|
+
const resetState = useVerifierReset();
|
|
496
|
+
|
|
497
|
+
useEffect(() => {
|
|
498
|
+
if (authError?.includes("Failed to obtain auth token")) {
|
|
499
|
+
// Log critical error for debugging
|
|
500
|
+
console.error("Token exchange failed:", authError);
|
|
501
|
+
|
|
502
|
+
// Optionally send to error tracking service
|
|
503
|
+
// errorTrackingService.log(authError);
|
|
504
|
+
}
|
|
505
|
+
}, [authError]);
|
|
506
|
+
|
|
507
|
+
const handleRecovery = () => {
|
|
508
|
+
resetState();
|
|
509
|
+
setAuthError(null);
|
|
510
|
+
// User will need to restart authentication flow
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
if (!authError?.includes("Failed to obtain auth token")) {
|
|
514
|
+
return null;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
return (
|
|
518
|
+
<div className="critical-error">
|
|
519
|
+
<h3>Authentication Failed</h3>
|
|
520
|
+
<p>{authError}</p>
|
|
521
|
+
<p>Please try logging in again.</p>
|
|
522
|
+
<button onClick={handleRecovery}>
|
|
523
|
+
Start Over
|
|
524
|
+
</button>
|
|
525
|
+
</div>
|
|
526
|
+
);
|
|
527
|
+
};
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
### Complete Error Handling Example
|
|
531
|
+
|
|
532
|
+
Here's a comprehensive example showing how to handle all error types in a consumer application:
|
|
533
|
+
|
|
534
|
+
```tsx
|
|
535
|
+
import { useContext, useEffect, useState } from 'react';
|
|
536
|
+
import { VContext, useVerifierReset } from "@abaxx_tech/v-integration-react";
|
|
537
|
+
|
|
538
|
+
const AuthErrorHandler = () => {
|
|
539
|
+
const { authError, setAuthError, isAuthenticating, token } = useContext(VContext);
|
|
540
|
+
const resetState = useVerifierReset();
|
|
541
|
+
const [errorType, setErrorType] = useState<'validation' | 'network' | 'connection' | 'token' | null>(null);
|
|
542
|
+
|
|
543
|
+
// Categorize error type
|
|
544
|
+
useEffect(() => {
|
|
545
|
+
if (!authError) {
|
|
546
|
+
setErrorType(null);
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
if (authError.includes("Invalid login")) {
|
|
551
|
+
setErrorType('validation');
|
|
552
|
+
} else if (authError.includes("Auth request failed") || authError.includes("Something went wrong")) {
|
|
553
|
+
setErrorType('network');
|
|
554
|
+
} else if (authError.includes("Connection") || authError.includes("Reconnecting")) {
|
|
555
|
+
setErrorType('connection');
|
|
556
|
+
} else if (authError.includes("Failed to obtain auth token")) {
|
|
557
|
+
setErrorType('token');
|
|
558
|
+
}
|
|
559
|
+
}, [authError]);
|
|
560
|
+
|
|
561
|
+
// Auto-dismiss validation errors after user interaction
|
|
562
|
+
useEffect(() => {
|
|
563
|
+
if (errorType === 'validation') {
|
|
564
|
+
const timer = setTimeout(() => setAuthError(null), 5000);
|
|
565
|
+
return () => clearTimeout(timer);
|
|
566
|
+
}
|
|
567
|
+
}, [errorType, setAuthError]);
|
|
568
|
+
|
|
569
|
+
const handleRetry = () => {
|
|
570
|
+
setAuthError(null);
|
|
571
|
+
// Trigger retry logic based on error type
|
|
572
|
+
if (errorType === 'connection' || errorType === 'token') {
|
|
573
|
+
resetState();
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
|
|
577
|
+
const handleDismiss = () => {
|
|
578
|
+
setAuthError(null);
|
|
579
|
+
};
|
|
580
|
+
|
|
581
|
+
if (!authError || !errorType) return null;
|
|
582
|
+
|
|
583
|
+
return (
|
|
584
|
+
<div className={`error-banner error-${errorType}`}>
|
|
585
|
+
<div className="error-content">
|
|
586
|
+
<span className="error-icon">⚠️</span>
|
|
587
|
+
<span className="error-message">{authError}</span>
|
|
588
|
+
</div>
|
|
589
|
+
<div className="error-actions">
|
|
590
|
+
{errorType === 'validation' && (
|
|
591
|
+
<button onClick={handleDismiss}>Dismiss</button>
|
|
592
|
+
)}
|
|
593
|
+
{(errorType === 'network' || errorType === 'connection') && (
|
|
594
|
+
<button onClick={handleRetry}>Retry</button>
|
|
595
|
+
)}
|
|
596
|
+
{errorType === 'token' && (
|
|
597
|
+
<button onClick={() => resetState()}>Start Over</button>
|
|
598
|
+
)}
|
|
599
|
+
</div>
|
|
600
|
+
</div>
|
|
601
|
+
);
|
|
602
|
+
};
|
|
603
|
+
|
|
604
|
+
// Usage in your app
|
|
605
|
+
const App = () => {
|
|
606
|
+
return (
|
|
607
|
+
<VerifierProvider apiUrl={API_URL} clientId={CLIENT_ID}>
|
|
608
|
+
<AuthErrorHandler />
|
|
609
|
+
<VerifierAuth title="My App" />
|
|
610
|
+
</VerifierProvider>
|
|
611
|
+
);
|
|
612
|
+
};
|
|
613
|
+
```
|
|
291
614
|
|
|
292
615
|
## Context API
|
|
293
616
|
|