how to fix this code it. it gives an error that can't push 2 calls must be only one. For this reason my login using firebase authentication doesn't work. i am not great with firebase i don't ge the documentation unfortunately.
// Sign up code in sessionStore
func signUp(email: String, password: String, completion: @escaping (_ error: Error?) -> Void) {
Auth.auth().createUser(withEmail: email, password: password) { (result, error) in
if let error = error {
print(error.localizedDescription)
} else {
completion(nil)
}
}
}
//sign in code for sign in view - particularly where * is placed is where i get the error that must take in one variable not 2 variables.
func signIn() {
session.signIn(email: email, password: password) { **(result, error)** in
if let error = error {
self.error = error.localizedDescription
} else {
return
}
}
}
// sign in in sessionStore
func signIn(email: String, password: String, completion:@escaping (_ error: Error?) -> Void) {
Auth.auth().signIn(withEmail: email, password: password) { (result, error) in
if let error = error {
print(error.localizedDescription)
} else {
completion(nil)
}
}
}
// code for sign in in sign in view also get the same error in the view
func signUp() {
session.signUp(email: email, password: password) {(result,_ error) in
if let error = error {
self.error = error.localizedDescription
} else {
self.email = ""
self.password = ""
}
}
}
i want to store users id in the firestore so i link a user's account to their data. Older solutions on stackoverflow don't work and so i want to re-ask this question.
In sessionStore
, your completion handler only sends back an Error?
:
func signIn(email: String, password: String, completion:@escaping (_ error: Error?) -> Void) {
But, you're attempting to use both a result
and error
when you call it here:
session.signIn(email: email, password: password) { (result, error) in
The simplest fix, if you don't need the result
, is to just change that line to:
session.signIn(email: email, password: password) { (error) in
Also, you currently aren't sending that error on in sessionStore
. Add this:
func signIn(email: String, password: String, completion:@escaping (_ error: Error?) -> Void) {
Auth.auth().signIn(withEmail: email, password: password) { (result, error) in
if let error = error {
print(error.localizedDescription)
completion(error) //<-- Here
} else {
completion(nil)
}
}
}
If you do need the result
in your signIn
function in your view, you could modify the signIn
function in sessionStore
to also return the result:
func signIn(email: String, password: String, completion:@escaping (AuthDataResult?,Error?) -> Void) {
Auth.auth().signIn(withEmail: email, password: password) { (result, error) in
completion(result, error)
}
}
In that case, you could keep your original (result, error)
code in your view.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.