[auth][android] verifyPhoneNumber implementation
This commit is contained in:
parent
3cde0e93d9
commit
73f7ceadcc
@ -1,6 +1,7 @@
|
|||||||
package io.invertase.firebase.auth;
|
package io.invertase.firebase.auth;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.os.Parcel;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
@ -730,7 +731,7 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
|||||||
* @param timeout
|
* @param timeout
|
||||||
*/
|
*/
|
||||||
@ReactMethod
|
@ReactMethod
|
||||||
public void verifyPhoneNumber(String appName, final String phoneNumber, final int timeout) {
|
public void verifyPhoneNumber(final String appName, final String phoneNumber, final String requestKey, final int timeout) {
|
||||||
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
|
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
|
||||||
final FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp);
|
final FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp);
|
||||||
final Activity activity = mReactContext.getCurrentActivity();
|
final Activity activity = mReactContext.getCurrentActivity();
|
||||||
@ -743,9 +744,18 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onVerificationCompleted(final PhoneAuthCredential phoneAuthCredential) {
|
public void onVerificationCompleted(final PhoneAuthCredential phoneAuthCredential) {
|
||||||
// User has been automatically verified, log them in
|
|
||||||
Log.d(TAG, "verifyPhoneNumber:verification:onVerificationCompleted");
|
Log.d(TAG, "verifyPhoneNumber:verification:onVerificationCompleted");
|
||||||
// todo
|
WritableMap state = Arguments.createMap();
|
||||||
|
Parcel p1 = Parcel.obtain();
|
||||||
|
|
||||||
|
phoneAuthCredential.writeToParcel(p1, 0);
|
||||||
|
String verificationId = p1.readString();
|
||||||
|
String smsCode = p1.readString();
|
||||||
|
|
||||||
|
p1.recycle();
|
||||||
|
state.putString("code", smsCode);
|
||||||
|
state.putString("verificationId", verificationId);
|
||||||
|
sendPhoneStateEvent(appName, requestKey, "onVerificationComplete", state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -754,25 +764,27 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
|||||||
// e.g. phone number format is incorrect, or the SMS quota for the project
|
// e.g. phone number format is incorrect, or the SMS quota for the project
|
||||||
// has been exceeded
|
// has been exceeded
|
||||||
Log.d(TAG, "verifyPhoneNumber:verification:onVerificationFailed");
|
Log.d(TAG, "verifyPhoneNumber:verification:onVerificationFailed");
|
||||||
WritableMap eventMap = Arguments.createMap();
|
WritableMap state = Arguments.createMap();
|
||||||
eventMap.putMap("error", getJSError(e));
|
state.putMap("error", getJSError(e));
|
||||||
Utils.sendEvent(mReactContext, "phone_auth_state_changed", eventMap);
|
sendPhoneStateEvent(appName, requestKey, "onVerificationFailed", state);
|
||||||
// todo
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCodeSent(String verificationId, PhoneAuthProvider.ForceResendingToken forceResendingToken) {
|
public void onCodeSent(String verificationId, PhoneAuthProvider.ForceResendingToken forceResendingToken) {
|
||||||
WritableMap verificationMap = Arguments.createMap();
|
// todo forceResendingToken ?
|
||||||
verificationMap.putString("verificationId", verificationId);
|
|
||||||
Log.d(TAG, "verifyPhoneNumber:verification:onCodeSent");
|
Log.d(TAG, "verifyPhoneNumber:verification:onCodeSent");
|
||||||
// todo
|
WritableMap state = Arguments.createMap();
|
||||||
|
state.putString("verificationId", verificationId);
|
||||||
|
sendPhoneStateEvent(appName, requestKey, "onCodeSent", state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCodeAutoRetrievalTimeOut(String verificationId) {
|
public void onCodeAutoRetrievalTimeOut(String verificationId) {
|
||||||
super.onCodeAutoRetrievalTimeOut(verificationId);
|
super.onCodeAutoRetrievalTimeOut(verificationId);
|
||||||
Log.d(TAG, "verifyPhoneNumber:verification:onCodeAutoRetrievalTimeOut");
|
Log.d(TAG, "verifyPhoneNumber:verification:onCodeAutoRetrievalTimeOut");
|
||||||
// todo
|
WritableMap state = Arguments.createMap();
|
||||||
|
state.putString("verificationId", verificationId);
|
||||||
|
sendPhoneStateEvent(appName, requestKey, "onCodeAutoRetrievalTimeout", state);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -1327,4 +1339,19 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
|||||||
|
|
||||||
return userMap;
|
return userMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param appName
|
||||||
|
* @param requestKey
|
||||||
|
* @param type
|
||||||
|
* @param state
|
||||||
|
*/
|
||||||
|
private void sendPhoneStateEvent(String appName, String requestKey, String type, WritableMap state) {
|
||||||
|
WritableMap eventMap = Arguments.createMap();
|
||||||
|
eventMap.putString("appName", appName);
|
||||||
|
eventMap.putString("requestKey", requestKey);
|
||||||
|
eventMap.putString("type", type);
|
||||||
|
eventMap.putMap("state", state);
|
||||||
|
Utils.sendEvent(mReactContext, "phone_auth_state_changed", eventMap);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user