Hello everyone, I'm just getting started with Swift and I'm in a bit of a knot here. Code below:
`if codeSent { TextField("6 Digit Code", text: $code)
Divider()
Button("Verify") {
print("verify...")
if code.count == 6 {
cloud(fun: "customSmsAuth", cloudData: [
"code": code,
"phoneNumber": phoneNumber
], completion: { resData in
let res = resData["res"] as? Int
if res == 1 {
let customToken = resData["customToken"]
Auth.auth().signIn(withCustomToken: customToken) { user, error in
}
} else {
print("An error occured...")
}
})
} else {
print("invalid code...")
}
}.padding()
}`
`else { HStack { Button("+26") { print("phone code...") }
TextField("Phone Number", text: $phoneNumber)
}
Divider()
Button("Send Code") {
print("send code...")
if phoneNumber.count == 10 {
cloud(fun: "sendSms", cloudData: ["phoneNumber" : "+26"+phoneNumber], completion: { resData in
let res = resData["res"] as? Int
if res == 1 {
codeSent = true
} else {
print("An error occured...")
}
})
} else {
print("Invalid phone number...")
}
print(phoneNumber)
}.padding()
}`
I'm trying to setup a simple phone based authentication with firebase. Any pointer where I'm going wrong will be appreciated.
Thanks.
Please note that the code works just fine without lines 43 to 46.