0
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

HangarRash
16.7k5 gold badges31 silver badges64 bronze badges
asked Nov 26, 2024 at 6:06
1
  • 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,. Commented Nov 26, 2024 at 16:24

1 Answer 1

0

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)")
 }
}
answered Nov 26, 2024 at 16:29
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much. This code got rid of the error.
Glad I could help. I just went and looked at the Swift docs for that framework and found the code I posted there.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.