I'm trying to check if a user is already registered or not in my app when registering. For every successful registration, I'm getting a UID in LoginViewcontroller
url and I'm saving that UID in the keychain wrapper. I'm retrieving the UID value in RegistrationViewController
regesterservice, but when I'm trying to check that UID I'm getting nil
all the time. Why..? how to check if a user is already registered or not? Please help me.
In LoginViewcontroller
login service, I'm saving the UID value like this:
self.Uid = json["id"] as? String
KeychainWrapper.standard.set(emailL ?? "", forKey: "user_email")
KeychainWrapper.standard.set(self.Uid!, forKey: "Uid")
Here, in RegisterViewController
, I retrieve the UID value. But for already registered persons, I'm also getting `nil in UID. Why?
do {
let userId: String? = KeychainWrapper.standard.string(forKey: "Uid")
print("login userid \(userId)")
if userId != nil{
AlertFun.ShowAlert(title: "Title", message: "user exist", in: self)
} else {
let json = try JSONSerialization.jsonObject(with: data, options: .mutableContainers) as! [String: Any]
print("go to otp service!!!")
self.otpField = json["otp"] as? Int
}
} catch {
print("error")
}
How can I query a UID of an already registered person?
In the first block of code, the Uid variable from the json is different from the Uid property being set in the keychain wrapper.
you can fix it by setting property to self instead of creating a separate variable
edit:
I'm sorry, I don't quite understand what you're saying. But I would try setting a breakpoint and debugging like this, and see which statement returns nil: