0

I am trying to make the following things:

  • Sign in with number and password. (Connect email/number)
  • Use one textfield for email/ number when the user can type one of the options and firebase will login in to that user account

I looked up at Firebase docs but there was not no mention about having Phone Number / Password auth.

For example, I signed up: email: SOME_MAIl password: SOME_PASSWORD number: SOME_NUMBER I want to make something like this

If numberAuth { Auth.auth.signIn(withNumber: number, password: password ) } else { Auth.auth.signIn(email: email, password: password ) } 

I found out that I have to customize firebase auth but I don't have an idea how to custom that. How that should be done?

P.S.: My idea is similar to this question Firebase Authentication connect Email with Phone

In the image below the idea is illustrated

Here is my code:

 func signIn() { if let password = passwordValue.text, let email = emailValue.text { Auth.auth().signIn(withEmail: email, password: password ) { [weak self] authResult, error in if let e = error { print(e) let alert = Service.createAlertController(title: "Error", message: e.localizedDescription) self?.present(alert, animated: true,completion: nil) } else { let storyboard = UIStoryboard(name: "Main", bundle: nil) let vc = storyboard.instantiateViewController(identifier: "main") vc.modalPresentationStyle = .overFullScreen self?.present(vc, animated: true) } } } } 

enter image description here

8
  • I am not really sure what you're asking; the code in the question is email authentication. What are you trying to do beyond that, and do you have some code you've attempted we can take a look at? Commented Aug 4, 2021 at 17:39
  • So, I want to make email + password auth and phone + password auth. The user enter either number or email in first textfield. I want to customize my func with email auth. I looked up in firebase documentation there is nothing more about this case that I want to do. The idea what I want to is similar to this stackoverflow.com/questions/44677846/… Commented Aug 4, 2021 at 18:21
  • Isn't this just a matter of evaluating what the user entered? If it's an email, then use email authentication, of it parses to a phone number, use that. Right? Commented Aug 4, 2021 at 20:48
  • @Jay yes, I can add some if else for that, but there would happen duplicate numbers in firebase database. 1 number would be in 2 different users. For example, I signed up: email: SOME_MAIl password: SOME_PASSWORD number: SOME_NUMBER I want to make something like this If numberAuth { Auth.auth.signIn(withNumber: number, password: password ) } else { Auth.auth.signIn(email: email, password: password ) } Commented Aug 5, 2021 at 4:22
  • Firebase authentication doesn't allow duplicate emails or numbers and will throw an error in those situations right up front so you can notify the user. So this... 1 number would be in 2 different users ...can't actually happen. Commented Aug 5, 2021 at 17:44

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.