简体   繁体   中英

Firebase verify phone number then authenticate user with email/password with Swift

I am building an app in Swift using Firebase. I want to authenticate user with email and password, but before create an account I need to verify the user's phone number. I tried several ways but I'm still struggling with this issue .

I successfully Authenticated a user with Phone Number (I followed the great tutorial for the phone auth in Authenticate with Firebase on iOS using a Phone Number ) and successfully Authenticated a user with email and password (I also followed the tutorials in Authenticate with Firebase using Password-Based Accounts on iOS ).

But I can't verify the user's phone number and then authenticate the user with his email , password and attach the verified phone number with other user information such as ( unique username , PhotoURL ...etc).

There are a couple of ways to achieve this. First and foremost, based on my experience its better you verify the users phone before going to authenticate them, like you are trying to do. I am assuming its an iOS app

I do not think firebase has that functionality built in natively. You may have to use some other third party solutions like Snich - https://www.sinch.com/products/verification/ or nexmo - https://www.nexmo.com/ . Personally I have only used nexmo in my previous implementations So I could guide you through that path. You would need to create an account here - https://dashboard.nexmo.com/sign-up

When done, login and click on Verify at the top of the page, look to your left hand side of the page you will find Create an application. Click on it and create an application with your app name, specify the options you want based on your apps preference. When done an app secrete and app id will be generated for you. Please note it down.

Now am assuming you already have pod setup in your project, so I will not go into that. I mean for you to have firebase implemented then you have pod setup in your project. Add the nexmoverify sdk to your project by doing this: pod 'NexmoVerify'

The github repo for nexmoverify is: https://github.com/Nexmo/verify-ios-sdk

Go through their repo it will guide you.

You can then integrate Nexmo verify SDK into your project by following this guide - https://docs.nexmo.com/verify/verify-sdk-for-iOS/integration

That should get you going. If you encounter any challenge let me know and I will guide you

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM