Closed Dave-London closed 1 year ago
Thanks for opening this @Dave-London.
Does it work as expected if you remove the print statements in the create
closure? Alternatively, just the second one and add a return
statement before Amplify.Auth.resetPassword(for:)
/ Amplify.Auth.confirmResetPassword(for:with:confirmationCode:)
?
For example:
Amplify.Publisher.create {
print("going to call Amplify.Auth.resetPassword.")
return try await Amplify.Auth.resetPassword(for: email)
}.sink {
if case let .failure(authError) = $0 {
print("Reset password failed with error \(authError)")
}
} receiveValue: { resetResult in
print("got reset result for Amplify.Auth.resetPassword: \(resetResult)")
}
The Amplify.Publisher.create
is generic over the return type of the closure; it returns AnyPublisher<Success, Error>
with Success
being dependent what you return in the closure passed into it.
In your example, the closure returns Void
due to the print statements. Changing to what I suggested above will also resolve the warning you're likely seeing ⚠️ Result of call to 'resetPassword(for:options:)' is unused
.
The examples in our documentation use implicit returns - we should probably add an explicit return statement to those examples to make the intent clearer.
Hi @atierian, tried using the code you provided and got the same behaviour - the reset password request was processed and i got an email with a verification code, but the sink wasn't triggered with any event - error or result.
Ok, thanks for the update. We'll investigate and come back with any updates or follow up questions.
@Dave-London are you holding on to the cancellable
anywhere - either by assigning it to stored property or .store(in &cancellables)
?
Looking over your example again, it's not clear that's happening.
that was the issue. it was missing and after i added .store() the functions work as expected.
Thanks @atierian
Great, happy to hear!
There's an opportunity to improve our documentation here to make this clearer. Thanks again for opening the issue.
Describe the bug
I'm trying to implement a "forgot password" flow in my iOS app, and facing an issue when using Amplify.Auth.resetPassword & Amplify.Auth.confirmResetPassword with Combine - I call the functions as instructed in the example provided in the Amplify dev docs, and while the actual action seems to work (for resetPassword - I get an email with a verification code as expected, for confirmResetPassword - the provided new password becomes the one in use - validated using web app and appsync console), I never get an event with a result or error in the sink attached to the Amplify.Publisher.
Steps To Reproduce
Expected behavior
once the request is completed - the sink should be triggered with either an error or a result, like it is explained in your documentation - https://docs.amplify.aws/lib/auth/password_management/q/platform/ios/
Amplify Framework Version
2.17.1 & 2.17.2
Amplify Categories
Auth
Dependency manager
Swift PM
Swift version
5.8, 5.9
CLI version
11.0.0 & 12.4.0
Xcode version
Xcode 15.0 Build version 15A240d, also happened before update to 15.0
Relevant log output
Is this a regression?
No
Regression additional context
No response
Platforms
iOS
OS Version
16.4, 17.0
Device
physical iPhone 12 as well as iPhone 14 & 15 simulators
Specific to simulators
no
Additional context