diff --git a/EXAMPLES.md b/EXAMPLES.md index 24d975ec..8d92f2c5 100644 --- a/EXAMPLES.md +++ b/EXAMPLES.md @@ -443,6 +443,33 @@ ngOnInit() { } ``` +If a token request from `getAccessTokenSilently` or `AuthHttpInterceptor` fails (for example, the device is offline or a browser extension blocks it), the SDK emits a `NetworkError` after retrying. If the request times out, it emits a `TimeoutError` instead. Without refresh tokens, the SDK first loads an iframe, which can't detect network failures, so being offline usually gives a `TimeoutError`. + +These errors don't mean the user's session is invalid, so show an offline message or retry later instead of asking the user to log in again. `PopupTimeoutError` is also a `TimeoutError`, but it means the user didn't finish a popup login in time, so the example leaves it out: + +```ts +import { filter } from 'rxjs/operators'; +import { + NetworkError, + PopupTimeoutError, + TimeoutError, +} from '@auth0/auth0-angular'; + +ngOnInit() { + this.authService.error$.pipe( + filter( + (e) => + (e instanceof NetworkError || e instanceof TimeoutError) && + !(e instanceof PopupTimeoutError) + ) + ).subscribe(() => { + // temporary network issue: show an offline message or retry later + }); +} +``` + +If the login callback fails this way, `error$` also emits a `NetworkError` or `TimeoutError`, and the SDK navigates to `errorPath` (or `/` if it isn't set). The login can't be retried, so call `loginWithRedirect` once the network is back. + ## Organizations [Organizations](https://auth0.com/docs/organizations) is a set of features that provide better support for developers who build and maintain SaaS and Business-to-Business (B2B) applications. diff --git a/package-lock.json b/package-lock.json index 1f2ef30b..942641de 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@angular/core": "^20.3.35", "@angular/platform-browser": "^20.3.35", "@angular/router": "^20.3.35", - "@auth0/auth0-spa-js": "^2.30.0", + "@auth0/auth0-spa-js": "^2.31.0", "rxjs": "^6.6.7", "tslib": "^2.9.1", "zone.js": "~0.15.1" @@ -1011,8 +1011,8 @@ } }, "node_modules/@auth0/auth0-spa-js": { - "version": "2.30.0", - "integrity": "sha512-jqsVox2+TiBZf0Zh5h9iITh7W6a/WCGAMLuqniz+PTg2afVggbOBDmieo1zwOp8zQoY3RPguN4l5mvLDmxu7EQ==", + "version": "2.31.0", + "integrity": "sha512-/9HaDEuJtOm15IB1EyXMyvYr1b2IMzg6TvnVKgB0B592h9or2SH9/6w4vJnR2NkKoKYLk7aL9fQrTVIfHhHSNQ==", "license": "MIT", "dependencies": { "@auth0/auth0-auth-js": "^1.17.0", diff --git a/package.json b/package.json index b7f5a37e..10283170 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "@angular/core": "^20.3.35", "@angular/platform-browser": "^20.3.35", "@angular/router": "^20.3.35", - "@auth0/auth0-spa-js": "^2.30.0", + "@auth0/auth0-spa-js": "^2.31.0", "rxjs": "^6.6.7", "tslib": "^2.9.1", "zone.js": "~0.15.1" diff --git a/projects/auth0-angular/package.json b/projects/auth0-angular/package.json index feb69ce2..b424e4d3 100644 --- a/projects/auth0-angular/package.json +++ b/projects/auth0-angular/package.json @@ -32,7 +32,7 @@ }, "dependencies": { "tslib": "^2.0.0", - "@auth0/auth0-spa-js": "^2.30.0" + "@auth0/auth0-spa-js": "^2.31.0" }, "schematics": "./schematics/collection.json" } diff --git a/projects/auth0-angular/src/public-api.spec.ts b/projects/auth0-angular/src/public-api.spec.ts index 5544d48f..4a1814ef 100644 --- a/projects/auth0-angular/src/public-api.spec.ts +++ b/projects/auth0-angular/src/public-api.spec.ts @@ -16,6 +16,7 @@ vi.mock('@auth0/auth0-spa-js', async (importOriginal) => { import { GenericError, isFederatedDomain, + NetworkError, PasskeyVerificationRequiredError, } from './public-api'; @@ -63,4 +64,16 @@ describe('public-api', () => { expect(error.verificationRequired).toEqual(['email']); }); }); + + describe('Network errors', () => { + it('re-exports NetworkError from spa-js, so instanceof checks match', async () => { + const spa = await import('@auth0/auth0-spa-js'); + const error = new spa.NetworkError('Failed to fetch'); + + expect(NetworkError).toBe(spa.NetworkError); + expect(error).toBeInstanceOf(NetworkError); + expect(error).toBeInstanceOf(GenericError); + expect(error.error).toBe('network_error'); + }); + }); }); diff --git a/projects/auth0-angular/src/public-api.ts b/projects/auth0-angular/src/public-api.ts index 1203e4d8..3fbc2c57 100644 --- a/projects/auth0-angular/src/public-api.ts +++ b/projects/auth0-angular/src/public-api.ts @@ -31,6 +31,7 @@ export { User, GenericError, TimeoutError, + NetworkError, MfaRequiredError, PopupTimeoutError, PopupOpenError,