Skip to content

Commit b73cb09

Browse files
docs: address review feedback on EXAMPLES.md
1 parent 51fee7a commit b73cb09

1 file changed

Lines changed: 38 additions & 11 deletions

File tree

EXAMPLES.md

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,14 +1018,14 @@ Access MFA operations through the `mfa` property on `AuthService`. All operation
10181018
> [!NOTE]
10191019
> Multi Factor Authentication support via SDKs is currently in Early Access. To request access to this feature, contact your Auth0 representative.
10201020
1021-
- [Setup](#setup)
1021+
- [Setup](#mfa-setup)
10221022
- [Handling MFA Required Error](#handling-mfa-required-error)
10231023
- [Enrolling Authenticators](#enrolling-authenticators)
10241024
- [Challenging Authenticators](#challenging-authenticators)
10251025
- [Verifying Challenges](#verifying-challenges)
10261026
- [Error Handling](#mfa-error-handling)
10271027
1028-
### Setup
1028+
### MFA Setup
10291029
10301030
Before using the MFA API, configure MFA in your [Auth0 Dashboard](https://manage.auth0.com) under **Security** > **Multi-factor Auth**. For detailed configuration, see the [Auth0 MFA documentation](https://auth0.com/docs/secure/multi-factor-authentication/customize-mfa/customize-mfa-enrollments-universal-login).
10311031
@@ -1071,7 +1071,7 @@ Catch the `MfaRequiredError` from `getAccessTokenSilently` and use `mfa_requirem
10711071
```ts
10721072
import { Component } from '@angular/core';
10731073
import { AuthService, MfaRequiredError } from '@auth0/auth0-angular';
1074-
import { catchError, EMPTY, switchMap } from 'rxjs';
1074+
import { catchError, EMPTY, tap } from 'rxjs';
10751075

10761076
@Component({ selector: 'app-mfa', template: '' })
10771077
export class MfaComponent {
@@ -1087,14 +1087,18 @@ export class MfaComponent {
10871087

10881088
if (error.mfa_requirements?.enroll?.length) {
10891089
// New user — needs to enroll a factor first
1090-
this.auth.mfa.getEnrollmentFactors(mfaToken).subscribe((factors) => {
1091-
// Show enrollment UI with available factors
1092-
});
1090+
return this.auth.mfa.getEnrollmentFactors(mfaToken).pipe(
1091+
tap((factors) => {
1092+
// Show enrollment UI with available factors
1093+
})
1094+
);
10931095
} else {
10941096
// Existing user — list enrolled authenticators and challenge
1095-
this.auth.mfa.getAuthenticators(mfaToken).subscribe((authenticators) => {
1096-
// Show challenge UI
1097-
});
1097+
return this.auth.mfa.getAuthenticators(mfaToken).pipe(
1098+
tap((authenticators) => {
1099+
// Show challenge UI
1100+
})
1101+
);
10981102
}
10991103
}
11001104
return EMPTY;
@@ -1307,7 +1311,7 @@ If you need full control over the MFA experience (custom UI for enrollment, chal
13071311
> [!WARNING]
13081312
> This feature only works with the refresh token flow (`useRefreshTokens: true`) and only handles `mfa_required` errors.
13091313
1310-
### Setup
1314+
### Step-Up Setup
13111315
13121316
Configure `provideAuth0` (or `AuthModule.forRoot`) with `interactiveErrorHandler` set to `"popup"` and refresh tokens enabled:
13131317
@@ -1388,4 +1392,27 @@ export class ProtectedComponent {
13881392
13891393
### Error Handling
13901394
1391-
If the popup is blocked, cancelled, or times out, `getAccessTokenSilently` throws `PopupOpenError`, `PopupCancelledError`, or `PopupTimeoutError` respectively. These can be imported from `@auth0/auth0-angular`.
1395+
If the popup is blocked, cancelled, or times out, `getAccessTokenSilently` throws `PopupOpenError`, `PopupCancelledError`, or `PopupTimeoutError` respectively. These can be imported from `@auth0/auth0-angular`:
1396+
1397+
```ts
1398+
import { PopupOpenError, PopupCancelledError, PopupTimeoutError } from '@auth0/auth0-angular';
1399+
import { catchError, EMPTY } from 'rxjs';
1400+
1401+
this.auth
1402+
.getAccessTokenSilently({
1403+
authorizationParams: { audience: 'https://api.example.com/' },
1404+
})
1405+
.pipe(
1406+
catchError((error) => {
1407+
if (error instanceof PopupOpenError) {
1408+
console.error('Popup was blocked by the browser');
1409+
} else if (error instanceof PopupCancelledError) {
1410+
console.error('User closed the popup');
1411+
} else if (error instanceof PopupTimeoutError) {
1412+
console.error('Popup timed out');
1413+
}
1414+
return EMPTY;
1415+
})
1416+
)
1417+
.subscribe();
1418+
```

0 commit comments

Comments
 (0)