You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-**Generic OAuth Providers** (GitHub, Microsoft, Yahoo, or custom OIDC)
268
268
269
+
### Reauthentication in Default Views
270
+
271
+
Sensitive operations like deleting accounts, updating passwords, or unenrolling MFA factors require recent authentication. When using default views, reauthentication is handled automatically based on the user's sign-in provider.
272
+
273
+
#### Automatic Reauthentication Behavior
274
+
275
+
When a sensitive operation requires reauthentication, the default views automatically:
276
+
277
+
-**OAuth Providers (Google, Apple, Facebook, Twitter, etc.)**: Display an alert asking the user to confirm, then automatically obtain fresh credentials and complete the operation.
278
+
279
+
-**Email/Password**: Present a sheet prompting the user to enter their password before continuing.
280
+
281
+
-**Phone**: Show an alert explaining verification is needed, then present a sheet for SMS code verification.
282
+
283
+
The operation automatically retries after successful reauthentication. No additional code is required when using `AuthPickerView` or the built-in account management views (`UpdatePasswordView`, `SignedInView`, etc.).
284
+
269
285
---
270
286
271
287
## Usage with Custom Views
@@ -635,6 +651,76 @@ When building custom views, you need to handle several things yourself that `Aut
635
651
3.**Anonymous User Upgrades**: Handle the linking of anonymous accounts if `shouldAutoUpgradeAnonymousUsers` is enabled
636
652
4.**Navigation State**: Manage navigation between different auth screens (phone verification, password recovery, etc.)
637
653
5.**Loading States**: Show loading indicators during async authentication operations by observing `authService.authenticationState`
654
+
6.**Reauthentication**: Handle reauthentication errors for sensitive operations (see [Reauthentication in Custom Views](#reauthentication-in-custom-views) below)
655
+
656
+
### Reauthentication in Custom Views
657
+
658
+
When building custom views, handle reauthentication by catching specific errors and implementing your own flow. Sensitive operations throw three types of reauthentication errors, each containing context information.
Enables email authentication and will render email sign-in directly within the AuthPickerView (default Views), email link sign-in is rendered as a button. When calling `AuthService.renderButtons()`, email link sign-in button is rendered. `onTap` custom callback (i.e where to navigate when tapped) allows user to control what happens when tapped. Default behavior in AuthPickerView is to push the user to email link sign-in default View.
774
860
775
861
**Parameters:**
776
-
-`provider`: An optional instance of `EmailProviderSwift`. If not provided, a default instance will be created.
777
862
-`onTap`: A callback that will be executed when the email button is tapped.
778
863
779
864
**Example:**
@@ -1213,12 +1298,15 @@ Updates the current user's photo URL.
Updates the current user's password. May require recent authentication.
1301
+
Updates the current user's password. This is a sensitive operation that may require recent authentication.
1217
1302
1218
1303
**Parameters:**
1219
1304
-`password`: New password
1220
1305
1221
-
**Throws:**`AuthServiceError.noCurrentUser` or Firebase Auth errors
1306
+
**Throws:**
1307
+
-`AuthServiceError.noCurrentUser` if no user is signed in
1308
+
- Reauthentication errors (`emailReauthenticationRequired`, `phoneReauthenticationRequired`, or `oauthReauthenticationRequired`) if recent authentication is required - see [Reauthentication](#reauthentication-in-default-views)
1309
+
- Firebase Auth errors
1222
1310
1223
1311
---
1224
1312
@@ -1240,7 +1328,42 @@ Sends a verification email to the current user's email address.
1240
1328
publicfuncdeleteUser() asyncthrows
1241
1329
```
1242
1330
1243
-
Deletes the current user's account. May require recent authentication.
1331
+
Deletes the current user's account. This is a sensitive operation that requires recent authentication.
1332
+
1333
+
**Throws:**
1334
+
-`AuthServiceError.noCurrentUser` if no user is signed in
1335
+
- Reauthentication errors (`emailReauthenticationRequired`, `phoneReauthenticationRequired`, or `oauthReauthenticationRequired`) if recent authentication is required - see [Reauthentication](#reauthentication-in-default-views)
Reauthenticates the current user with an OAuth provider (Google, Apple, Facebook, Twitter, etc.). Automatically locates the registered provider, obtains fresh credentials, and completes reauthentication.
1347
+
1348
+
**Parameters:**
1349
+
-`context`: The reauth context from `oauthReauthenticationRequired` error
1350
+
1351
+
**Throws:**`AuthServiceError.noCurrentUser` or `AuthServiceError.providerNotFound`
1352
+
1353
+
**Note:** Only works for OAuth providers. For email/phone, use `reauthenticate(with:)`.
**Default Behavior:** If no custom coordinator is provided, a default `PasswordPromptCoordinator()` instance is created automatically. The default coordinator displays a modal sheet that prompts the user to enter their password when reauthentication is required for sensitive operations (e.g., updating email, deleting account).
1439
-
1440
-
---
1441
-
1442
1549
```swift
1443
1550
publicvar authView: AuthView?
1444
1551
```
@@ -1539,9 +1646,14 @@ public enum AuthServiceError: Error {
1539
1646
Errors specific to `AuthService` operations.
1540
1647
1541
1648
**Reauthentication Errors:**
1542
-
-`oauthReauthenticationRequired`: For OAuth providers like Google, Apple, Facebook, Twitter. Pass the context to `authService.reauthenticate(context:)`.
1543
-
-`emailReauthenticationRequired`: For email/password authentication. Must handle password prompt externally.
1544
-
-`phoneReauthenticationRequired`: For phone authentication. Must handle SMS verification flow externally.
1649
+
1650
+
Thrown by sensitive operations when Firebase requires recent authentication. Each includes context information:
1651
+
1652
+
-**`oauthReauthenticationRequired(context: OAuthReauthContext)`**: OAuth providers. Context contains `providerId`, `providerName`, and `displayMessage`. Pass to `reauthenticate(context:)`.
1653
+
1654
+
-**`emailReauthenticationRequired(context: EmailReauthContext)`**: Email/password provider. Context contains `email` and `displayMessage`. Prompt for password, then call `reauthenticate(with:)`.
1655
+
1656
+
-**`phoneReauthenticationRequired(context: PhoneReauthContext)`**: Phone provider. Context contains `phoneNumber` and `displayMessage`. Handle SMS verification, then call `reauthenticate(with:)`.
1545
1657
1546
1658
---
1547
1659
@@ -1559,6 +1671,8 @@ Errors specific to `AuthService` operations.
1559
1671
1560
1672
6.**Provider-specific setup**: Some providers (Google, Facebook) require additional configuration in AppDelegate or Info.plist. See the [sample app](https://github.com/firebase/FirebaseUI-iOS/tree/main/samples/swiftui) for examples.
1561
1673
1674
+
7.**Handle reauthentication**: Default views handle reauthentication automatically. For custom views, catch and handle reauthentication errors when performing sensitive operations like `deleteUser()`, `updatePassword()`, and `unenrollMFA()`. See [Reauthentication in Custom Views](#reauthentication-in-custom-views).
0 commit comments