Skip to content

Commit

Permalink
Updated FAQ to include workaround for transaction active error (#885)
Browse files Browse the repository at this point in the history
Co-authored-by: Rita Zerrizuela <zeta@widcket.com>
  • Loading branch information
pmathew92 and Widcket authored Nov 13, 2024
1 parent 4ee4de5 commit f2d44bc
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- [2. How can I disable the _logout_ alert box?](#2-how-can-i-disable-the-logout-alert-box)
- [3. How can I change the message in the alert box?](#3-how-can-i-change-the-message-in-the-alert-box)
- [4. How can I programmatically close the alert box?](#4-how-can-i-programmatically-close-the-alert-box)
- [5. How to resolve the _Failed to start this transaction, as there is an active transaction at the moment_ error?](#5-how-to-resolve-the-failed-to-start-this-transaction-as-there-is-an-active-transaction-at-the-moment-error)

---

Expand Down Expand Up @@ -140,6 +141,31 @@ Auth0.swift has no control whatsoever over the alert box. Its contents cannot be

Auth0.swift has no control whatsoever over the alert box. It cannot be closed programmatically. Unfortunately, that is a limitation of `ASWebAuthenticationSession`.

---
## 5. How to resolve the _Failed to start this transaction, as there is an active transaction at the moment_ error?

Users might encounter this error when the app moves to the background and then back to the foreground while the login/logout alert box is displayed, for example by locking and unlocking the device. The alert box would get dismissed but when the user tries to log in again, the Web Auth operation fails with the `transactionActiveAlready` error.

This is a known issue with `ASWebAuthenticationSession` and it is not specific to Auth0.swift. We have already filed a bug report with Apple and are awaiting for a response from them.

### Workarounds

#### Clear the login transaction when handling the `transactionActiveAlready` error

You can invoke `WebAuthentication.cancel()` to manually clear the current login transaction upon encountering this error. Then, you can retry login. For example:

```swift
switch error {
case .failure(let error) where error == .transactionActiveAlready:
WebAuthentication.cancel()
// ... retry login
// ...
}
```

#### Clear the login transaction when the app moves to the background/foreground
You can invoke `WebAuthentication.cancel()` to manually clear the current login transaction when the app moves to the background or back to the foreground. However, you need to make sure to not cancel valid login attempts –for example, when the user switches briefly to another app while the login page is open.

#### Avoid the login/logout alert box
If you don't need SSO, consider using `ephemeral sessions` or `SFSafariViewController` instead of `ASWebAuthenticationSession`. See [1. How can I disable the _login_ alert box?](#1-how-can-i-disable-the-login-alert-box) for more information.

[Go up ⤴](#frequently-asked-questions)

0 comments on commit f2d44bc

Please sign in to comment.