ios - Two user types in Swift -
i trying make app 2 different user types. there 2 different home screens want route depending on type of user logging in. not able either user type respective home screen.
edit: updated code
@ibaction func signinbuttonpress(_ sender: uibutton) { //check if email , password fields filled , todo- valid if let email = emailtextfield.text, let pass = passwordtextfield.text { //sign in user firebase auth.auth().signin(withemail: email, password: pass) { (user, error) in //check user not nil if user != nil { let userid = auth.auth().currentuser?.uid self.ref.child("users").child(userid!).child("accounttype").observesingleevent(of: .value, with: {(snapshot) in if let accounttype = snapshot.value as? string{ // have retrieved account type // segue if accounttype == "user1"{ self.performsegue(withidentifier: "gotohome1", sender: self) } if accounttype == "user2"{ self.performsegue(withidentifier: "gotohome2", sender: self) } else{ print("error1") } } else{ print("error2") // there no node found in database // named 'accounttype' } } )} } } }
Comments
Post a Comment