-
Notifications
You must be signed in to change notification settings - Fork 15
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
feat: Invoke DetermineAuthMethodUseCase
- WPB-15920
#2532
base: develop
Are you sure you want to change the base?
Conversation
So it can become identifiable
# Conflicts: # WireAuthentication/Sources/WireAuthenticationAPI/Use cases/DetermineAuthMethodUseCase.swift
...ication/Sources/WireAuthenticationUI/Views/DetermineAuthMethod/DetermineAuthMethodView.swift
Outdated
Show resolved
Hide resolved
...ication/Sources/WireAuthenticationUI/Views/DetermineAuthMethod/DetermineAuthMethodView.swift
Outdated
Show resolved
Hide resolved
@@ -61,7 +61,6 @@ package struct DetermineAuthMethodView: View { | |||
.padding(.trailing) | |||
|
|||
VStack(alignment: .leading, spacing: 8) { | |||
// TODO: [WPB-16045] Set error on `LabeledTextField` when supported. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer needed
@@ -70,21 +69,14 @@ package struct DetermineAuthMethodView: View { | |||
) | |||
.lineLimit(nil) | |||
.fixedSize(horizontal: false, vertical: true) | |||
|
|||
if let errorMessage = viewModel.errorMessage { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer needed
...on/Sources/WireAuthenticationUI/Views/DetermineAuthMethod/DetermineAuthMethodViewModel.swift
Outdated
Show resolved
Hide resolved
// TODO: [WPB-15920] Handle on-prem login | ||
do { | ||
// TODO: Fix concurrency issue | ||
let method = try await determineAuthMethod.invoke(emailOrSSOCode: emailOrSSOCode) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@KaterinaWire I haven't yet managed to fix this concurrency warning. One solution is to do:
let task = Task.detached { [determineAuthMethod, emailOrSSOCode] in
try await determineAuthMethod.invoke(emailOrSSOCode: emailOrSSOCode)
}
let method = try await task.value
However the typed error becomes untyped with this which is a little annoying.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@samwyndham I marked invoke(emailOrSSOCode:)
as @mainactor, maybe as a temp solution. We still have same warnings in DetermineAuthMethodUseCase
and need to find a proper solution
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there are a few ways to solve this that we should explore, but if we mark the use case as main actor, then we must ensure appropriate concurrency inside the use case implementation.
@samwyndham if you don't want to lose the error type you could catch inside the task and return a typed error in the result. This adds a bit of boilerplate, so it could be factored out in a utility extension so the API looks something like:
try await Task.detached<Success, Failure> {
...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we instead declare DetermineAuthMethodUseCaseProtocol
as Sendable
and everything else which is needed for the compiler to not produce Sendable
related warnings?
Like AuthenticationAPI
etc.
Test Results24 tests 24 ✅ 7s ⏱️ Results for commit 50558b1. ♻️ This comment has been updated with latest results. |
Datadog ReportBranch report: ✅ 0 Failed, 19 Passed, 0 Skipped, 7.58s Total Time |
@@ -20,11 +20,12 @@ import Foundation | |||
|
|||
public protocol DetermineAuthMethodUseCaseProtocol { | |||
|
|||
@MainActor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: I thought about this in the past whether use cases should be invoked on the main thread and internally they manage their own concurrency, or if we should instead defer that thought to the caller (i.e a view model which is marked as MainActor). Perhaps it's a topic for the architecture forum.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion the @MainActor
requirement here on the protocol should be removed.
Since invoke
is declared async
anyhow, it's up to the implementation to decide, whether it should run on the main actor or not.
@@ -117,28 +119,56 @@ package struct DetermineAuthMethodView: View { | |||
|
|||
} | |||
|
|||
// MARK: - Private helpers | |||
|
|||
private func titleForAlert(_ alert: DetermineAuthMethodViewModel.Alert) -> Text { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
praise: nice way to keep the view code a more readable.
// TODO: [WPB-15920] Handle on-prem login | ||
do { | ||
// TODO: Fix concurrency issue | ||
let method = try await determineAuthMethod.invoke(emailOrSSOCode: emailOrSSOCode) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there are a few ways to solve this that we should explore, but if we mark the use case as main actor, then we must ensure appropriate concurrency inside the use case implementation.
@samwyndham if you don't want to lose the error type you could catch inside the task and return a typed error in the result. This adds a bit of boilerplate, so it could be factored out in a utility extension so the API looks something like:
try await Task.detached<Success, Failure> {
...
}
@@ -20,11 +20,12 @@ import Foundation | |||
|
|||
public protocol DetermineAuthMethodUseCaseProtocol { | |||
|
|||
@MainActor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion the @MainActor
requirement here on the protocol should be removed.
Since invoke
is declared async
anyhow, it's up to the implementation to decide, whether it should run on the main actor or not.
@@ -97,6 +89,16 @@ package struct DetermineAuthMethodView: View { | |||
.disabled(viewModel.isNextButtonEnabled || viewModel.isLoading) | |||
}.padding() | |||
} | |||
.alert(item: $viewModel.alert) { alert in | |||
Alert( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't Alert
deprecated?
https://developer.apple.com/documentation/swiftui/alert
// TODO: [WPB-15920] Handle on-prem login | ||
do { | ||
// TODO: Fix concurrency issue | ||
let method = try await determineAuthMethod.invoke(emailOrSSOCode: emailOrSSOCode) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we instead declare DetermineAuthMethodUseCaseProtocol
as Sendable
and everything else which is needed for the compiler to not produce Sendable
related warnings?
Like AuthenticationAPI
etc.
Issue
This PR invokes
DetermineAuthMethodUseCase
. When this is mergedDetermineAuthMethodView
should be largely complete, excluding the route navigation ofloginViaSSO
&onPremLogin
.Testing
Run unit tests
Checklist
[WPB-XXX]
.