Firebase Phone Number Auth integration
Is the new Firebase Phone number Auth on the roadmap?
Yeah it will be. Will look at seeing what's possible to do
@jasan-s @Ehesp - might make sense to wait until android support is out for this at the end of may: https://firebase.google.com/docs/auth/android/phone-auth
They will support this? Awesome 😄
Since I currently use Facebook Account Kit to verify phone numbers, I actually consider waiting with my first release until I can use it with firebase.
I believe its already available as they have open sourced their SDKs
@jeveloper it's only available in ios at the moment
ohh thats odd, i thought they were just reusing fabrics digits which works on anything
thanks man!
Maybe now is too early June :)
Phone number sign-in is coming soon to Firebase on Android. Check this page in early June 2017 for details.
Yesterday it said late May! :)
+1 I am also really interested in this feature!
+1 We're anxiously awaiting this feature after Google finishes implementation for Android
https://firebase.google.com/support/release-notes/android#20170607
Now available on Android SDK!
Is anyone assigned or already working a PR to this issue? If not, I could try to do it myself.
@Sparragus no one specifically. I'll take a look at Android on Monday if theres no PR. IOS looks a bit too complicated for my object c skills
I've been looking into this today. I'll have to speak internally about how to actually implement this (more best practice). The aim of this lib is to try and replicate the web SDK, however I don't think it'll be possible here.
- On the Web docs there's no need for steps 1-3.
signInWithPhoneNumbertakes a phoneNumber & appVerifier (where appVerifier is redundant on the device).- The native SDKs (at least on Android) takes a
verifyPhoneNumber. It can also do things like auto detection. The response of which, can be directly passed intosignInWithCredential.
@chrisbianca @Salakar How do you suggest dealing with the following workflow:
After calling verifyPhoneNumber, we return a promise which would resolve on onVerificationCompleted (Instantly verified or auto detected). The issue is though, there's an optional onCodeSent which would prompt the user to enter the code manually (as it's not been detected automagically). How would that fit into the API?
firebase.auth().verifyPhoneNumber('+441234567')
.then((credential) => {}) // onVerificationCompleted
.catch(() => {});
That may potentially never get called, as it's hit the onCodeSent block. We could add a method like verifyPhoneCode or something, but then how would the user know whether to use this or not.
Hello, I successfully got it working for iOS. Unfortunately I don't have the time for a PR but I will describe how I went on. First, the NativeModule (my module is called WHOFirebaseAuth here)
//
// WHOFirebaseAuth.m
// WhoCaresAppNew
//
// Created by Enes Kaya on 29.05.17.
// Copyright © 2017 Facebook. All rights reserved.
//
#import "WHOFirebaseAuth.h"
#import <FirebaseAuth/FirebaseAuth.h>
@implementation WHOFirebaseAuth
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(verifyPhoneNumber:(NSString*) userInput
callback:(RCTResponseSenderBlock) callback)
{
[[FIRPhoneAuthProvider provider]
verifyPhoneNumber: userInput
completion:^(NSString * _Nullable verificationID, NSError * _Nullable error) {
NSLog(@"WHOFirebaseAuth: %@", userInput);
if (error) {
callback(@[error.localizedDescription, @"ERROR"]);
NSLog(@"WHOFirebaseAuth: %@", error.localizedDescription);
} else {
// Sets the verficiationID in UserDefaults for later usage
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:verificationID forKey:@"authVerificationID"];
callback(@[[NSNull null], verificationID]);
}
}];
}
RCT_EXPORT_METHOD(getVerificationId:(RCTResponseSenderBlock)callback)
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *verificationID = [defaults stringForKey:@"authVerificationID"];
callback(@[[NSNull null], verificationID]);
}
@end
You call it like this in your RN project:
const WHOFirebaseAuth = NativeModules.WHOFirebaseAuth
...
static sendVerificationCodeTo(phoneNumber) {
return new Promise((resolve, reject) => {
WHOFirebaseAuth.verifyPhoneNumber(
phoneNumber,
(error, verificationID) => {
if (!error) {
resolve({
error: null,
verificationID: verificationID
})
} else {
reject({
error,
verificationID: null
})
}
}
)
})
}
...
After that, if it was successful, the user get's the code sent via SMS. Then you can log in like so:
/**
* Signs the user in with PhoneAuth credential.
*
* @param {[type]} verificationID The verificationID returned by this.sendVerificationCodeTo
* @param {[type]} code The code which was sent via SMS
* @return {[type]} firebase.Promise containing non-null firebase.User
*/
static signInWithPhoneAuth(verificationID, code) {
var credential = firebase.auth.PhoneAuthProvider.credential(
verificationID,
code
)
return firebase.auth().signInWithCredential(credential)
}
So, basically it's a mix between the native SDK and the JS SDK. Remember to install Firebase/Auth via CocoaPods in version >4.0.0.
Hope that helps, for me it's working perfectly.
@eneskaya will it work on android with same syntax and all ?
@yash2code The JS part of the code yes, but obviously not the objective-c part. I will, later today implement the android side.
@eneskaya Any thought on my comment above regarding onCodeSent would be handy on Android.
@eneskaya Ty sir, I m surely waiting for that !! :)
@Ehesp not yet, but will look into that. I'll keep you posted