import Amplify
class Auth {
var email: String?
var password: String?
// Login
func login(email: String, password: String, completion: @escaping (String?) -> Void) {
Amplify.Auth.signIn(username: email, password: password) { result in // Error: Extra trailing closure passed in call
switch result {
case .success:
completion("Success")
case .failure(let error):
completion("Login failed: \(error.errorDescription)")
}
}
}
// Forgot Password
func forgotPassword(email: String, completion: @escaping (String?) -> Void) {
Amplify.Auth.resetPassword(for: email) { result in //Error: Extra trailing closure passed in call
switch result {
case .success:
completion("Password reset code sent to \(email).")
case .failure(let error):
completion("Password reset failed: \(error.errorDescription)")
}
}
}
Error:
Extra trailing closure passed in call.
I’m working on an iOS app using Amplify and AWSCognitoAuthPlugin for authentication. I'm using UIKit for development and have created an authentication class to handle login, forgot password, verify email, and resend verification code. However, I’m encountering an error when trying to perform authentication methods like signIn, resetPassword, and others.
enter image description here
I tried to use "AWSCognitoIdentityProviderService" but I want to use Amplify completely for my IOS App
-
Always include code as formatted text, not images. If you want to show the error, show a screenshot ALSO. Also show us the definition of that function. I've never used Amplify and am not going to download it in order to answer your question,.Duncan C– Duncan C2024年11月26日 16:24:43 +00:00Commented Nov 26, 2024 at 16:24
1 Answer 1
It looks like it was rewritten to use async/await. I found this sample code using the function. It does not take a closure, but instead returns a signInResult.
func signIn(username: String, password: String) async {
do {
let signInResult = try await Amplify.Auth.signIn(
username: username,
password: password
)
if signInResult.isSignedIn {
print("Sign in succeeded")
}
} catch let error as AuthError {
print("Sign in failed \(error)")
} catch {
print("Unexpected error: \(error)")
}
}