Skip to content

Added webAuth cancel for ios to prevent active transaction errors #573

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

pmathew92
Copy link
Contributor

Changes

This PR added support to cancel any ongoing transaction on iOS while using UL

References

https://github.com/auth0/Auth0.swift/blob/master/FAQ.md#5-how-to-resolve-the-failed-to-start-this-transaction-as-there-is-an-active-transaction-at-the-moment-error

  • [] All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

@@ -0,0 +1 @@
../../../darwin/Classes/WebAuth/WebAuthCancelMethodHandler.swift

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need these changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean the WebAuthCancelMethodHandler class ?

@@ -49,6 +49,13 @@ public class WebAuthHandler: NSObject, FlutterPlugin {
}

public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {

if call.method == "webAuth#cancel" {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest to have the call method name as part of string constants

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding this as part of the existing Method enum was failing the UTs as all the corresponding handlers expect arguments. Fixing that would require adding some explicit conditions in UTs and code which weren't looking good

webAuth.cancelWebAuth();
//Retry login
}
}
Copy link
Contributor

@Widcket Widcket May 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the formatting of the code snippet. A code snippet that is not properly formatted hinders readability.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

@Widcket Widcket May 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The if braces are at the same level as those from the catch, and the if block itself is not indented, whereas the contents of the try block are.

Screenshot 2025-05-07 at 15 00 34

/// You need to call this method within your custom Web Auth provider implementation whenever the operation is
/// cancelled by the user.
/// ## Note:
/// This is an iOS specific api
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// This is an iOS specific api
/// This is an iOS specific API.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, should it be a static method or not?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason to declare it as static ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, it depends on how it's going to be used. In the case of the Auth0.swift SDK, the cancel() method is meant to be called on its own (even possibly on the App Delegate) in circumstances where there is no expectation of an existing instance being around. Not sure what the usage would look like on Flutter apps, hence the question.

@Widcket
Copy link
Contributor

Widcket commented May 7, 2025

Please check the failing Android unit tests. Maybe something needs updating.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants