0

I trying to call the login function for user to perform their login action, the way I calling the function is as follow:

struct LogInView: View {    
    @State  private var emailAddress: String = ""
    @State  private var password: String = ""
    @EnvironmentObject var userAuth: UserAuth

    var body: some View {
    ...
      Button(action: {
                    userAuth.login(self.emailAddress, self.password)
                }) {
                       HStack {
                           Text("Sign In as Owner")
                       }
                           .padding()
                           .frame(width: geometry.size.width - 40, height: 40)
                           .foregroundColor(Color.white)
                           .background(Color.blue)
                           .cornerRadius(5)
                   }
    ...
    }

And below is how I declare my login function

class UserAuth: ObservableObject {
    @Published var isLoggedIn = false
    var userID = nil {
        didSet {
            didChange.send(self)
        }
    }
    var UserModel = PersistenceController()
    
    let didChange = PassthroughSubject<UserAuth,Never>()
    
    // required to conform to protocol 'ObservableObject'
    let willChange = PassthroughSubject<UserAuth,Never>()
    
    func login(email: String, password: String) {
        self.userID = UserModel.loginUser(email: email, password: password).id
        self.isLoggedin = true
      }
   }

I am really confused, the function is accepting two parameters, but the error keep showing "Argument passed to call that takes no arguments". Anyone knows how to solve it? Thanks in Advance.

Hanyi Koh
  • 327
  • 1
  • 4
  • 15
  • Is that the complete implementation of your `Button` ? Then the error message is probably a red hering. You would need to fix the Button. – burnsi Sep 06 '22 at 00:46
  • show a complete minimal example code: https://stackoverflow.com/help/minimal-reproducible-example that highlights your error, --> `red herring`. Try also `Button("click me", action: { userAuth.login(self.emailAddress, self.password) })` – workingdog support Ukraine Sep 06 '22 at 00:56
  • @burnsi Not the complete button implementation, I just updated it. The button works for other pages, but for this particular login function, it keep failing. – Hanyi Koh Sep 06 '22 at 02:10
  • @workingdogsupportUkraine Thank you for the code, I tried but still no use :') – Hanyi Koh Sep 06 '22 at 02:11

1 Answers1

0

Try this:

userAuth.login(email: self.emailAddress, password: self.password)