mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-01-12 17:42:24 +08:00
[auth][[ios][js] deprecate all *AndRetrieveData* methods on auth() and User
This commit is contained in:
@@ -104,12 +104,12 @@ dependencies {
|
||||
compileOnly "com.google.firebase:firebase-auth:16.0.3"
|
||||
compileOnly "com.google.firebase:firebase-config:16.0.0"
|
||||
compileOnly "com.google.firebase:firebase-crash:16.2.0"
|
||||
compileOnly "com.google.firebase:firebase-database:16.0.1"
|
||||
compileOnly "com.google.firebase:firebase-database:16.0.2"
|
||||
compileOnly "com.google.firebase:firebase-firestore:17.1.0"
|
||||
compileOnly "com.google.firebase:firebase-functions:16.1.0"
|
||||
compileOnly "com.google.firebase:firebase-invites:16.0.3"
|
||||
compileOnly "com.google.firebase:firebase-storage:16.0.1"
|
||||
compileOnly "com.google.firebase:firebase-messaging:17.3.0"
|
||||
compileOnly "com.google.firebase:firebase-storage:16.0.2"
|
||||
compileOnly "com.google.firebase:firebase-messaging:17.3.2"
|
||||
compileOnly "com.google.firebase:firebase-perf:16.1.0"
|
||||
compileOnly 'me.leolin:ShortcutBadger:1.1.21@aar'
|
||||
}
|
||||
|
||||
@@ -1,10 +1,30 @@
|
||||
#import "RNFirebaseAuth.h"
|
||||
#import "RNFirebaseEvents.h"
|
||||
#import "RNFirebaseUtil.h"
|
||||
#import "RCTDefines.h"
|
||||
|
||||
#if __has_include(<FirebaseAuth/FIRAuth.h>)
|
||||
|
||||
static NSString *const keyIOS = @"iOS";
|
||||
static NSString *const keyUrl = @"url";
|
||||
static NSString *const keyUid = @"uid";
|
||||
static NSString *const keyUser = @"user";
|
||||
static NSString *const keyEmail = @"email";
|
||||
static NSString *const keyAndroid = @"android";
|
||||
static NSString *const keyProfile = @"profile";
|
||||
static NSString *const keyNewUser = @"isNewUser";
|
||||
static NSString *const keyUsername = @"username";
|
||||
static NSString *const keyPhotoUrl = @"photoURL";
|
||||
static NSString *const keyBundleId = @"bundleId";
|
||||
static NSString *const keyInstallApp = @"installApp";
|
||||
static NSString *const keyProviderId = @"providerId";
|
||||
static NSString *const keyPhoneNumber = @"phoneNumber";
|
||||
static NSString *const keyDisplayName = @"displayName";
|
||||
static NSString *const keyPackageName = @"packageName";
|
||||
static NSString *const keyMinVersion = @"minimumVersion";
|
||||
static NSString *const constAppLanguage = @"APP_LANGUAGE";
|
||||
static NSString *const keyHandleCodeInApp = @"handleCodeInApp";
|
||||
static NSString *const keyAdditionalUserInfo = @"additionalUserInfo";
|
||||
|
||||
@implementation RNFirebaseAuth
|
||||
RCT_EXPORT_MODULE();
|
||||
|
||||
@@ -18,8 +38,8 @@ RCT_EXPORT_MODULE();
|
||||
}
|
||||
|
||||
/**
|
||||
addAuthStateListener
|
||||
|
||||
* addAuthStateListener
|
||||
*
|
||||
*/
|
||||
RCT_EXPORT_METHOD(addAuthStateListener:
|
||||
(NSString *) appDisplayName) {
|
||||
@@ -30,7 +50,7 @@ RCT_EXPORT_METHOD(addAuthStateListener:
|
||||
[[FIRAuth authWithApp:firApp] addAuthStateDidChangeListener:^(FIRAuth *_Nonnull auth, FIRUser *_Nullable user) {
|
||||
if (user != nil) {
|
||||
[RNFirebaseUtil sendJSEventWithAppName:self app:firApp name:AUTH_STATE_CHANGED_EVENT body:@{
|
||||
@"user": [self firebaseUserToDict:user]}];
|
||||
keyUser: [self firebaseUserToDict:user]}];
|
||||
} else {
|
||||
[RNFirebaseUtil sendJSEventWithAppName:self app:firApp name:AUTH_STATE_CHANGED_EVENT body:@{}];
|
||||
}
|
||||
@@ -41,8 +61,8 @@ RCT_EXPORT_METHOD(addAuthStateListener:
|
||||
}
|
||||
|
||||
/**
|
||||
removeAuthStateListener
|
||||
|
||||
* removeAuthStateListener
|
||||
*
|
||||
*/
|
||||
RCT_EXPORT_METHOD(removeAuthStateListener:
|
||||
(NSString *) appDisplayName) {
|
||||
@@ -55,8 +75,8 @@ RCT_EXPORT_METHOD(removeAuthStateListener:
|
||||
}
|
||||
|
||||
/**
|
||||
addIdTokenListener
|
||||
|
||||
* addIdTokenListener
|
||||
*
|
||||
*/
|
||||
RCT_EXPORT_METHOD(addIdTokenListener:
|
||||
(NSString *) appDisplayName) {
|
||||
@@ -67,7 +87,7 @@ RCT_EXPORT_METHOD(addIdTokenListener:
|
||||
[[FIRAuth authWithApp:firApp] addIDTokenDidChangeListener:^(FIRAuth *_Nonnull auth, FIRUser *_Nullable user) {
|
||||
if (user != nil) {
|
||||
[RNFirebaseUtil sendJSEventWithAppName:self app:firApp name:AUTH_ID_TOKEN_CHANGED_EVENT body:@{
|
||||
@"user": [self firebaseUserToDict:user]}];
|
||||
keyUser: [self firebaseUserToDict:user]}];
|
||||
} else {
|
||||
[RNFirebaseUtil sendJSEventWithAppName:self app:firApp name:AUTH_ID_TOKEN_CHANGED_EVENT body:@{}];
|
||||
}
|
||||
@@ -148,38 +168,13 @@ RCT_EXPORT_METHOD(signInAnonymously:
|
||||
(RCTPromiseResolveBlock) resolve
|
||||
rejecter:
|
||||
(RCTPromiseRejectBlock) reject) {
|
||||
[self signInAnonymously:appDisplayName withData:false resolver:resolve rejecter:reject];
|
||||
}
|
||||
|
||||
/**
|
||||
signInAnonymouslyAndRetrieveData
|
||||
|
||||
@param RCTPromiseResolveBlock resolve
|
||||
@param RCTPromiseRejectBlock reject
|
||||
@return
|
||||
*/
|
||||
RCT_EXPORT_METHOD(signInAnonymouslyAndRetrieveData:
|
||||
(NSString *) appDisplayName
|
||||
resolver:
|
||||
(RCTPromiseResolveBlock) resolve
|
||||
rejecter:
|
||||
(RCTPromiseRejectBlock) reject) {
|
||||
[self signInAnonymously:appDisplayName withData:true resolver:resolve rejecter:reject];
|
||||
}
|
||||
|
||||
- (void)signInAnonymously:(NSString *)appDisplayName
|
||||
withData:(BOOL)withData
|
||||
resolver:(RCTPromiseResolveBlock)resolve
|
||||
rejecter:(RCTPromiseRejectBlock)reject {
|
||||
FIRApp *firApp = [RNFirebaseUtil getApp:appDisplayName];
|
||||
|
||||
[[FIRAuth authWithApp:firApp] signInAnonymouslyWithCompletion:^(FIRAuthDataResult *authResult, NSError *error) {
|
||||
if (error) {
|
||||
[self promiseRejectAuthException:reject error:error];
|
||||
} else if (withData) {
|
||||
[self promiseWithAuthResult:resolve rejecter:reject authResult:authResult];
|
||||
} else {
|
||||
[self promiseWithUser:resolve rejecter:reject user:authResult.user];
|
||||
[self promiseWithAuthResult:resolve rejecter:reject authResult:authResult];
|
||||
}
|
||||
}];
|
||||
}
|
||||
@@ -194,28 +189,6 @@ RCT_EXPORT_METHOD(signInAnonymouslyAndRetrieveData:
|
||||
@return return
|
||||
*/
|
||||
RCT_EXPORT_METHOD(signInWithEmailAndPassword:
|
||||
(NSString *) appDisplayName
|
||||
email:
|
||||
(NSString *) email
|
||||
pass:
|
||||
(NSString *) password
|
||||
resolver:
|
||||
(RCTPromiseResolveBlock) resolve
|
||||
rejecter:
|
||||
(RCTPromiseRejectBlock) reject) {
|
||||
[self signInWithEmail:appDisplayName email:email password:password withData:false resolver:resolve rejecter:reject];
|
||||
}
|
||||
|
||||
/**
|
||||
signInAndRetrieveDataWithEmailAndPassword
|
||||
|
||||
@param NSString NSString email
|
||||
@param NSString NSString password
|
||||
@param RCTPromiseResolveBlock resolve
|
||||
@param RCTPromiseRejectBlock reject
|
||||
@return return
|
||||
*/
|
||||
RCT_EXPORT_METHOD(signInAndRetrieveDataWithEmailAndPassword:
|
||||
(NSString *) appDisplayName
|
||||
email:
|
||||
(NSString *) email
|
||||
@@ -225,25 +198,14 @@ RCT_EXPORT_METHOD(signInAndRetrieveDataWithEmailAndPassword:
|
||||
(RCTPromiseResolveBlock) resolve
|
||||
rejecter:
|
||||
(RCTPromiseRejectBlock) reject) {
|
||||
[self signInWithEmail:appDisplayName email:email password:password withData:true resolver:resolve rejecter:reject];
|
||||
}
|
||||
|
||||
- (void)signInWithEmail:(NSString *)appDisplayName
|
||||
email:(NSString *)email
|
||||
password:(NSString *)password
|
||||
withData:(BOOL)withData
|
||||
resolver:(RCTPromiseResolveBlock)resolve
|
||||
rejecter:(RCTPromiseRejectBlock)reject {
|
||||
FIRApp *firApp = [RNFirebaseUtil getApp:appDisplayName];
|
||||
|
||||
[[FIRAuth authWithApp:firApp] signInWithEmail:email password:password completion:^(FIRAuthDataResult *authResult,
|
||||
NSError *error) {
|
||||
if (error) {
|
||||
[self promiseRejectAuthException:reject error:error];
|
||||
} else if (withData) {
|
||||
[self promiseWithAuthResult:resolve rejecter:reject authResult:authResult];
|
||||
} else {
|
||||
[self promiseWithUser:resolve rejecter:reject user:authResult.user];
|
||||
[self promiseWithAuthResult:resolve rejecter:reject authResult:authResult];
|
||||
}
|
||||
}];
|
||||
}
|
||||
@@ -288,29 +250,8 @@ RCT_EXPORT_METHOD(signInWithEmailLink:
|
||||
@param RCTPromiseRejectBlock reject
|
||||
@return return
|
||||
*/
|
||||
RCT_EXPORT_METHOD(createUserWithEmailAndPassword:
|
||||
(NSString *) appDisplayName
|
||||
email:
|
||||
(NSString *) email
|
||||
pass:
|
||||
(NSString *) password
|
||||
resolver:
|
||||
(RCTPromiseResolveBlock) resolve
|
||||
rejecter:
|
||||
(RCTPromiseRejectBlock) reject) {
|
||||
[self createUserWithEmail:appDisplayName email:email password:password withData:false resolver:resolve rejecter:reject];
|
||||
}
|
||||
|
||||
/**
|
||||
createUserAndRetrieveDataWithEmailAndPassword
|
||||
|
||||
@param NSString NSString email
|
||||
@param NSString NSString password
|
||||
@param RCTPromiseResolveBlock resolve
|
||||
@param RCTPromiseRejectBlock reject
|
||||
@return return
|
||||
*/
|
||||
RCT_EXPORT_METHOD(createUserAndRetrieveDataWithEmailAndPassword:
|
||||
RCT_EXPORT_METHOD(createUserWithEmailAndPassword:
|
||||
(NSString *) appDisplayName
|
||||
email:
|
||||
(NSString *) email
|
||||
@@ -320,25 +261,14 @@ RCT_EXPORT_METHOD(createUserAndRetrieveDataWithEmailAndPassword:
|
||||
(RCTPromiseResolveBlock) resolve
|
||||
rejecter:
|
||||
(RCTPromiseRejectBlock) reject) {
|
||||
[self createUserWithEmail:appDisplayName email:email password:password withData:true resolver:resolve rejecter:reject];
|
||||
}
|
||||
|
||||
- (void)createUserWithEmail:(NSString *)appDisplayName
|
||||
email:(NSString *)email
|
||||
password:(NSString *)password
|
||||
withData:(BOOL)withData
|
||||
resolver:(RCTPromiseResolveBlock)resolve
|
||||
rejecter:(RCTPromiseRejectBlock)reject {
|
||||
FIRApp *firApp = [RNFirebaseUtil getApp:appDisplayName];
|
||||
|
||||
[[FIRAuth authWithApp:firApp] createUserWithEmail:email password:password completion:^(FIRAuthDataResult *authResult,
|
||||
NSError *error) {
|
||||
if (error) {
|
||||
[self promiseRejectAuthException:reject error:error];
|
||||
} else if (withData) {
|
||||
[self promiseWithAuthResult:resolve rejecter:reject authResult:authResult];
|
||||
} else {
|
||||
[self promiseWithUser:resolve rejecter:reject user:authResult.user];
|
||||
[self promiseWithAuthResult:resolve rejecter:reject authResult:authResult];
|
||||
}
|
||||
}];
|
||||
}
|
||||
@@ -529,7 +459,8 @@ RCT_EXPORT_METHOD(updatePhoneNumber:
|
||||
FIRUser *user = [FIRAuth authWithApp:firApp].currentUser;
|
||||
|
||||
if (user) {
|
||||
FIRAuthCredential *credential = [self getCredentialForProvider:provider token:authToken secret:authSecret];
|
||||
FIRPhoneAuthCredential *credential =
|
||||
(FIRPhoneAuthCredential *) [self getCredentialForProvider:provider token:authToken secret:authSecret];
|
||||
|
||||
if (credential == nil) {
|
||||
return reject(@"auth/invalid-credential",
|
||||
@@ -576,7 +507,7 @@ RCT_EXPORT_METHOD(updateProfile:
|
||||
|
||||
for (NSString *key in allKeys) {
|
||||
@try {
|
||||
if ([key isEqualToString:@"photoURL"]) {
|
||||
if ([key isEqualToString:keyPhotoUrl]) {
|
||||
NSURL *url = [NSURL URLWithString:[props valueForKey:key]];
|
||||
[changeRequest setValue:url forKey:key];
|
||||
} else {
|
||||
@@ -653,41 +584,6 @@ RCT_EXPORT_METHOD(signInWithCredential:
|
||||
(RCTPromiseResolveBlock) resolve
|
||||
rejecter:
|
||||
(RCTPromiseRejectBlock) reject) {
|
||||
[self signInWithCredential:appDisplayName provider:provider token:authToken secret:authSecret withData:false resolver:resolve rejecter:reject];
|
||||
}
|
||||
|
||||
/**
|
||||
signInAndRetrieveDataWithCredential
|
||||
|
||||
@param NSString provider
|
||||
@param NSString authToken
|
||||
@param NSString authSecret
|
||||
@param RCTPromiseResolveBlock resolve
|
||||
@param RCTPromiseRejectBlock reject
|
||||
@return
|
||||
*/
|
||||
RCT_EXPORT_METHOD(signInAndRetrieveDataWithCredential:
|
||||
(NSString *) appDisplayName
|
||||
provider:
|
||||
(NSString *) provider
|
||||
token:
|
||||
(NSString *) authToken
|
||||
secret:
|
||||
(NSString *) authSecret
|
||||
resolver:
|
||||
(RCTPromiseResolveBlock) resolve
|
||||
rejecter:
|
||||
(RCTPromiseRejectBlock) reject) {
|
||||
[self signInWithCredential:appDisplayName provider:provider token:authToken secret:authSecret withData:true resolver:resolve rejecter:reject];
|
||||
}
|
||||
|
||||
- (void)signInWithCredential:(NSString *)appDisplayName
|
||||
provider:(NSString *)provider
|
||||
token:(NSString *)authToken
|
||||
secret:(NSString *)authSecret
|
||||
withData:(BOOL)withData
|
||||
resolver:(RCTPromiseResolveBlock)resolve
|
||||
rejecter:(RCTPromiseRejectBlock)reject {
|
||||
FIRApp *firApp = [RNFirebaseUtil getApp:appDisplayName];
|
||||
|
||||
FIRAuthCredential *credential = [self getCredentialForProvider:provider token:authToken secret:authSecret];
|
||||
@@ -702,10 +598,8 @@ RCT_EXPORT_METHOD(signInAndRetrieveDataWithCredential:
|
||||
NSError *error) {
|
||||
if (error) {
|
||||
[self promiseRejectAuthException:reject error:error];
|
||||
} else if (withData) {
|
||||
[self promiseWithAuthResult:resolve rejecter:reject authResult:authResult];
|
||||
} else {
|
||||
[self promiseWithUser:resolve rejecter:reject user:authResult.user];
|
||||
[self promiseWithAuthResult:resolve rejecter:reject authResult:authResult];
|
||||
}
|
||||
}];
|
||||
}
|
||||
@@ -808,9 +702,9 @@ RCT_EXPORT_METHOD(checkActionCode:
|
||||
NSMutableDictionary *data = [NSMutableDictionary dictionary];
|
||||
|
||||
if ([info dataForKey:FIRActionCodeEmailKey] != nil) {
|
||||
[data setValue:[info dataForKey:FIRActionCodeEmailKey] forKey:@"email"];
|
||||
[data setValue:[info dataForKey:FIRActionCodeEmailKey] forKey:keyEmail];
|
||||
} else {
|
||||
[data setValue:[NSNull null] forKey:@"email"];
|
||||
[data setValue:[NSNull null] forKey:keyEmail];
|
||||
}
|
||||
|
||||
if ([info dataForKey:FIRActionCodeFromEmailKey] != nil) {
|
||||
@@ -896,24 +790,6 @@ RCT_EXPORT_METHOD(sendSignInLinkToEmail:
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
signInAndRetrieveDataWithCustomToken
|
||||
|
||||
@param RCTPromiseResolveBlock resolve
|
||||
@param RCTPromiseRejectBlock reject
|
||||
@return
|
||||
*/
|
||||
RCT_EXPORT_METHOD(signInAndRetrieveDataWithCustomToken:
|
||||
(NSString *) appDisplayName
|
||||
customToken:
|
||||
(NSString *) customToken
|
||||
resolver:
|
||||
(RCTPromiseResolveBlock) resolve
|
||||
rejecter:
|
||||
(RCTPromiseRejectBlock) reject) {
|
||||
[self signInWithCustomToken:appDisplayName customToken:customToken withData:true resolver:resolve rejecter:reject];
|
||||
}
|
||||
|
||||
/**
|
||||
signInWithCustomToken
|
||||
|
||||
@@ -929,24 +805,14 @@ RCT_EXPORT_METHOD(signInWithCustomToken:
|
||||
(RCTPromiseResolveBlock) resolve
|
||||
rejecter:
|
||||
(RCTPromiseRejectBlock) reject) {
|
||||
[self signInWithCustomToken:appDisplayName customToken:customToken withData:false resolver:resolve rejecter:reject];
|
||||
}
|
||||
|
||||
- (void)signInWithCustomToken:(NSString *)appDisplayName
|
||||
customToken:(NSString *)customToken
|
||||
withData:(BOOL)withData
|
||||
resolver:(RCTPromiseResolveBlock)resolve
|
||||
rejecter:(RCTPromiseRejectBlock)reject {
|
||||
FIRApp *firApp = [RNFirebaseUtil getApp:appDisplayName];
|
||||
|
||||
[[FIRAuth authWithApp:firApp] signInWithCustomToken:customToken completion:^(FIRAuthDataResult *authResult,
|
||||
NSError *error) {
|
||||
if (error) {
|
||||
[self promiseRejectAuthException:reject error:error];
|
||||
} else if (withData) {
|
||||
[self promiseWithAuthResult:resolve rejecter:reject authResult:authResult];
|
||||
} else {
|
||||
[self promiseWithUser:resolve rejecter:reject user:authResult.user];
|
||||
[self promiseWithAuthResult:resolve rejecter:reject authResult:authResult];
|
||||
}
|
||||
}];
|
||||
}
|
||||
@@ -1035,6 +901,7 @@ RCT_EXPORT_METHOD(_confirmVerificationCode:
|
||||
FIRApp *firApp = [RNFirebaseUtil getApp:appDisplayName];
|
||||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
||||
NSString *verificationId = [defaults stringForKey:@"authVerificationID"];
|
||||
|
||||
FIRAuthCredential *credential =
|
||||
[[FIRPhoneAuthProvider provider] credentialWithVerificationID:verificationId verificationCode:verificationCode];
|
||||
|
||||
@@ -1070,41 +937,6 @@ RCT_EXPORT_METHOD(linkWithCredential:
|
||||
(RCTPromiseResolveBlock) resolve
|
||||
rejecter:
|
||||
(RCTPromiseRejectBlock) reject) {
|
||||
[self linkWithCredential:appDisplayName provider:provider authToken:authToken authSecret:authSecret withData:false resolver:resolve rejecter:reject];
|
||||
}
|
||||
|
||||
/**
|
||||
linkAndRetrieveDataWithCredential
|
||||
|
||||
@param NSString provider
|
||||
@param NSString authToken
|
||||
@param NSString authSecret
|
||||
@param RCTPromiseResolveBlock resolve
|
||||
@param RCTPromiseRejectBlock reject
|
||||
@return
|
||||
*/
|
||||
RCT_EXPORT_METHOD(linkAndRetrieveDataWithCredential:
|
||||
(NSString *) appDisplayName
|
||||
provider:
|
||||
(NSString *) provider
|
||||
authToken:
|
||||
(NSString *) authToken
|
||||
authSecret:
|
||||
(NSString *) authSecret
|
||||
resolver:
|
||||
(RCTPromiseResolveBlock) resolve
|
||||
rejecter:
|
||||
(RCTPromiseRejectBlock) reject) {
|
||||
[self linkWithCredential:appDisplayName provider:provider authToken:authToken authSecret:authSecret withData:true resolver:resolve rejecter:reject];
|
||||
}
|
||||
|
||||
- (void)linkWithCredential:(NSString *)appDisplayName
|
||||
provider:(NSString *)provider
|
||||
authToken:(NSString *)authToken
|
||||
authSecret:(NSString *)authSecret
|
||||
withData:(BOOL)withData
|
||||
resolver:(RCTPromiseResolveBlock)resolve
|
||||
rejecter:(RCTPromiseRejectBlock)reject {
|
||||
FIRApp *firApp = [RNFirebaseUtil getApp:appDisplayName];
|
||||
FIRAuthCredential *credential = [self getCredentialForProvider:provider token:authToken secret:authSecret];
|
||||
|
||||
@@ -1120,10 +952,8 @@ RCT_EXPORT_METHOD(linkAndRetrieveDataWithCredential:
|
||||
completion:^(FIRAuthDataResult *_Nullable authResult, NSError *_Nullable error) {
|
||||
if (error) {
|
||||
[self promiseRejectAuthException:reject error:error];
|
||||
} else if (withData) {
|
||||
[self promiseWithAuthResult:resolve rejecter:reject authResult:authResult];
|
||||
} else {
|
||||
[self promiseWithUser:resolve rejecter:reject user:authResult.user];
|
||||
[self promiseWithAuthResult:resolve rejecter:reject authResult:authResult];
|
||||
}
|
||||
}];
|
||||
} else {
|
||||
@@ -1187,41 +1017,6 @@ RCT_EXPORT_METHOD(reauthenticateWithCredential:
|
||||
(RCTPromiseResolveBlock) resolve
|
||||
rejecter:
|
||||
(RCTPromiseRejectBlock) reject) {
|
||||
[self reauthenticateWithCredential:appDisplayName provider:provider authToken:authToken authSecret:authSecret withData:false resolver:resolve rejecter:reject];
|
||||
}
|
||||
|
||||
/**
|
||||
reauthenticateAndRetrieveDataWithCredential
|
||||
|
||||
@param NSString provider
|
||||
@param NSString authToken
|
||||
@param NSString authSecret
|
||||
@param RCTPromiseResolveBlock resolve
|
||||
@param RCTPromiseRejectBlock reject
|
||||
@return
|
||||
*/
|
||||
RCT_EXPORT_METHOD(reauthenticateAndRetrieveDataWithCredential:
|
||||
(NSString *) appDisplayName
|
||||
provider:
|
||||
(NSString *) provider
|
||||
authToken:
|
||||
(NSString *) authToken
|
||||
authSecret:
|
||||
(NSString *) authSecret
|
||||
resolver:
|
||||
(RCTPromiseResolveBlock) resolve
|
||||
rejecter:
|
||||
(RCTPromiseRejectBlock) reject) {
|
||||
[self reauthenticateWithCredential:appDisplayName provider:provider authToken:authToken authSecret:authSecret withData:true resolver:resolve rejecter:reject];
|
||||
}
|
||||
|
||||
- (void)reauthenticateWithCredential:(NSString *)appDisplayName
|
||||
provider:(NSString *)provider
|
||||
authToken:(NSString *)authToken
|
||||
authSecret:(NSString *)authSecret
|
||||
withData:(BOOL)withData
|
||||
resolver:(RCTPromiseResolveBlock)resolve
|
||||
rejecter:(RCTPromiseRejectBlock)reject {
|
||||
FIRApp *firApp = [RNFirebaseUtil getApp:appDisplayName];
|
||||
|
||||
FIRAuthCredential *credential = [self getCredentialForProvider:provider token:authToken secret:authSecret];
|
||||
@@ -1239,10 +1034,8 @@ RCT_EXPORT_METHOD(reauthenticateAndRetrieveDataWithCredential:
|
||||
NSError *_Nullable error) {
|
||||
if (error) {
|
||||
[self promiseRejectAuthException:reject error:error];
|
||||
} else if (withData) {
|
||||
[self promiseWithAuthResult:resolve rejecter:reject authResult:authResult];
|
||||
} else {
|
||||
[self promiseWithUser:resolve rejecter:reject user:authResult.user];
|
||||
[self promiseWithAuthResult:resolve rejecter:reject authResult:authResult];
|
||||
}
|
||||
}];
|
||||
} else {
|
||||
@@ -1327,7 +1120,6 @@ RCT_EXPORT_METHOD(setLanguageCode:
|
||||
code:
|
||||
(NSString *) code) {
|
||||
FIRApp *firApp = [RNFirebaseUtil getApp:appDisplayName];
|
||||
|
||||
[FIRAuth authWithApp:firApp].languageCode = code;
|
||||
}
|
||||
|
||||
@@ -1340,7 +1132,6 @@ RCT_EXPORT_METHOD(setLanguageCode:
|
||||
RCT_EXPORT_METHOD(useDeviceLanguage:
|
||||
(NSString *) appDisplayName) {
|
||||
FIRApp *firApp = [RNFirebaseUtil getApp:appDisplayName];
|
||||
|
||||
[[FIRAuth authWithApp:firApp] useAppLanguage];
|
||||
}
|
||||
|
||||
@@ -1503,11 +1294,11 @@ RCT_EXPORT_METHOD(verifyPasswordResetCode:
|
||||
}
|
||||
|
||||
/**
|
||||
Resolve or reject a promise based on FIRUser value existance
|
||||
|
||||
@param resolve RCTPromiseResolveBlock
|
||||
@param reject RCTPromiseRejectBlock
|
||||
@param user FIRUser
|
||||
* Resolve or reject a promise based on FIRUser value existence
|
||||
*
|
||||
* @param resolve RCTPromiseResolveBlock
|
||||
* @param reject RCTPromiseRejectBlock
|
||||
* @param user FIRUser
|
||||
*/
|
||||
- (void)promiseWithUser:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject user:(FIRUser *)user {
|
||||
if (user) {
|
||||
@@ -1520,24 +1311,51 @@ RCT_EXPORT_METHOD(verifyPasswordResetCode:
|
||||
}
|
||||
|
||||
/**
|
||||
Resolve or reject a promise based on FIRAuthResult value existance
|
||||
|
||||
@param resolve RCTPromiseResolveBlock
|
||||
@param reject RCTPromiseRejectBlock
|
||||
@param authResult FIRAuthDataResult
|
||||
* Resolve or reject a promise based on FIRAuthResult value existence
|
||||
*
|
||||
* @param resolve RCTPromiseResolveBlock
|
||||
* @param reject RCTPromiseRejectBlock
|
||||
* @param authResult FIRAuthDataResult
|
||||
*/
|
||||
- (void)promiseWithAuthResult:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject authResult:(FIRAuthDataResult *)authResult {
|
||||
if (authResult && authResult.user) {
|
||||
NSDictionary *userDict = [self firebaseUserToDict:authResult.user];
|
||||
NSDictionary *authResultDict = @{
|
||||
@"additionalUserInfo": authResult.additionalUserInfo ? @{
|
||||
@"isNewUser": @(authResult.additionalUserInfo.isNewUser),
|
||||
@"profile": authResult.additionalUserInfo.profile ? authResult.additionalUserInfo.profile : [NSNull null],
|
||||
@"providerId": authResult.additionalUserInfo.providerID ? authResult.additionalUserInfo.providerID : [NSNull null],
|
||||
@"username": authResult.additionalUserInfo.username ? authResult.additionalUserInfo.username : [NSNull null]
|
||||
} : [NSNull null],
|
||||
@"user": userDict
|
||||
};
|
||||
NSMutableDictionary *authResultDict = [NSMutableDictionary dictionary];
|
||||
|
||||
// additionalUserInfo
|
||||
if (authResult.additionalUserInfo) {
|
||||
NSMutableDictionary *additionalUserInfo = [NSMutableDictionary dictionary];
|
||||
|
||||
// isNewUser
|
||||
[additionalUserInfo setValue:@(authResult.additionalUserInfo.isNewUser) forKey:keyNewUser];
|
||||
|
||||
// profile
|
||||
if (authResult.additionalUserInfo.profile) {
|
||||
[additionalUserInfo setValue:authResult.additionalUserInfo.profile forKey:keyProfile];
|
||||
} else {
|
||||
[additionalUserInfo setValue:[NSNull null] forKey:keyProfile];
|
||||
}
|
||||
|
||||
// providerId
|
||||
if (authResult.additionalUserInfo.providerID) {
|
||||
[additionalUserInfo setValue:authResult.additionalUserInfo.providerID forKey:keyProviderId];
|
||||
} else {
|
||||
[additionalUserInfo setValue:[NSNull null] forKey:keyProviderId];
|
||||
}
|
||||
|
||||
// username
|
||||
if (authResult.additionalUserInfo.username) {
|
||||
[additionalUserInfo setValue:authResult.additionalUserInfo.username forKey:keyUsername];
|
||||
} else {
|
||||
[additionalUserInfo setValue:[NSNull null] forKey:keyUsername];
|
||||
}
|
||||
|
||||
[authResultDict setValue:additionalUserInfo forKey:keyAdditionalUserInfo];
|
||||
} else {
|
||||
[authResultDict setValue:[NSNull null] forKey:keyAdditionalUserInfo];
|
||||
}
|
||||
|
||||
// user
|
||||
[authResultDict setValue:[self firebaseUserToDict:authResult.user] forKey:keyUser];
|
||||
resolve(authResultDict);
|
||||
} else {
|
||||
[self promiseNoUser:resolve rejecter:reject isError:YES];
|
||||
@@ -1546,10 +1364,10 @@ RCT_EXPORT_METHOD(verifyPasswordResetCode:
|
||||
}
|
||||
|
||||
/**
|
||||
Converts an array of FIRUserInfo instances into the correct format to match the web sdk
|
||||
|
||||
@param providerData FIRUser.providerData
|
||||
@return NSArray
|
||||
* Converts an array of FIRUserInfo instances into a web sdk compatible format
|
||||
*
|
||||
* @param providerData NSArray
|
||||
* @return NSArray
|
||||
*/
|
||||
- (NSArray <NSObject *> *)convertProviderData:(NSArray <id<FIRUserInfo>> *)providerData {
|
||||
NSMutableArray *output = [NSMutableArray array];
|
||||
@@ -1558,27 +1376,27 @@ RCT_EXPORT_METHOD(verifyPasswordResetCode:
|
||||
NSMutableDictionary *pData = [NSMutableDictionary dictionary];
|
||||
|
||||
if (userInfo.providerID != nil) {
|
||||
[pData setValue:userInfo.providerID forKey:@"providerId"];
|
||||
[pData setValue:userInfo.providerID forKey:keyProviderId];
|
||||
}
|
||||
|
||||
if (userInfo.uid != nil) {
|
||||
[pData setValue:userInfo.uid forKey:@"uid"];
|
||||
[pData setValue:userInfo.uid forKey:keyUid];
|
||||
}
|
||||
|
||||
if (userInfo.displayName != nil) {
|
||||
[pData setValue:userInfo.displayName forKey:@"displayName"];
|
||||
[pData setValue:userInfo.displayName forKey:keyDisplayName];
|
||||
}
|
||||
|
||||
if (userInfo.photoURL != nil) {
|
||||
[pData setValue:[userInfo.photoURL absoluteString] forKey:@"photoURL"];
|
||||
[pData setValue:[userInfo.photoURL absoluteString] forKey:keyPhotoUrl];
|
||||
}
|
||||
|
||||
if (userInfo.email != nil) {
|
||||
[pData setValue:userInfo.email forKey:@"email"];
|
||||
[pData setValue:userInfo.email forKey:keyEmail];
|
||||
}
|
||||
|
||||
if (userInfo.phoneNumber != nil) {
|
||||
[pData setValue:userInfo.phoneNumber forKey:@"phoneNumber"];
|
||||
[pData setValue:userInfo.phoneNumber forKey:keyPhoneNumber];
|
||||
}
|
||||
|
||||
[output addObject:pData];
|
||||
@@ -1589,33 +1407,33 @@ RCT_EXPORT_METHOD(verifyPasswordResetCode:
|
||||
|
||||
/**
|
||||
* React native constant exports - exports native firebase apps mainly
|
||||
*
|
||||
* @return NSDictionary
|
||||
*/
|
||||
- (NSDictionary *)constantsToExport {
|
||||
NSMutableDictionary *constants = [NSMutableDictionary new];
|
||||
NSDictionary *firApps = [FIRApp allApps];
|
||||
NSMutableDictionary *constants = [NSMutableDictionary new];
|
||||
NSMutableDictionary *appLanguage = [NSMutableDictionary new];
|
||||
|
||||
for (id key in firApps) {
|
||||
FIRApp *firApp = firApps[key];
|
||||
|
||||
appLanguage[firApp.name] = [FIRAuth authWithApp:firApp].languageCode;
|
||||
}
|
||||
|
||||
constants[@"APP_LANGUAGE"] = appLanguage;
|
||||
constants[constAppLanguage] = appLanguage;
|
||||
return constants;
|
||||
}
|
||||
|
||||
/**
|
||||
Converts a FIRUser instance into a dictionary to send via RNBridge
|
||||
|
||||
@param user FIRUser
|
||||
@return NSDictionary
|
||||
* Converts a FIRUser instance into a dictionary to send via RNBridge
|
||||
*
|
||||
* @param user FIRUser
|
||||
* @return NSDictionary
|
||||
*/
|
||||
- (NSDictionary *)firebaseUserToDict:(FIRUser *)user {
|
||||
return @{
|
||||
@"displayName": user.displayName ? user.displayName : [NSNull null],
|
||||
@"email": user.email ? user.email : [NSNull null],
|
||||
keyDisplayName: user.displayName ? user.displayName : [NSNull null],
|
||||
keyEmail: user.email ? user.email : [NSNull null],
|
||||
@"emailVerified": @(user.emailVerified),
|
||||
@"isAnonymous": @(user.anonymous),
|
||||
@"metadata": @{
|
||||
@@ -1624,36 +1442,49 @@ RCT_EXPORT_METHOD(verifyPasswordResetCode:
|
||||
@"lastSignInTime": user.metadata.lastSignInDate ? @(round(
|
||||
[user.metadata.lastSignInDate timeIntervalSince1970] * 1000.0)) : [NSNull null],
|
||||
},
|
||||
@"phoneNumber": user.phoneNumber ? user.phoneNumber : [NSNull null],
|
||||
@"photoURL": user.photoURL ? [user.photoURL absoluteString] : [NSNull null],
|
||||
keyPhoneNumber: user.phoneNumber ? user.phoneNumber : [NSNull null],
|
||||
keyPhotoUrl: user.photoURL ? [user.photoURL absoluteString] : [NSNull null],
|
||||
@"providerData": [self convertProviderData:user.providerData],
|
||||
@"providerId": [user.providerID lowercaseString],
|
||||
keyProviderId: [user.providerID lowercaseString],
|
||||
@"refreshToken": user.refreshToken,
|
||||
@"uid": user.uid
|
||||
keyUid: user.uid
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a FIRActionCodeSettings instance from JS args
|
||||
*
|
||||
* @param actionCodeSettings NSDictionary
|
||||
* @return FIRActionCodeSettings
|
||||
*/
|
||||
- (FIRActionCodeSettings *)buildActionCodeSettings:(NSDictionary *)actionCodeSettings {
|
||||
NSString *url = actionCodeSettings[keyUrl];
|
||||
NSDictionary *ios = actionCodeSettings[keyIOS];
|
||||
NSDictionary *android = actionCodeSettings[keyAndroid];
|
||||
BOOL handleCodeInApp = [actionCodeSettings[keyHandleCodeInApp] boolValue];
|
||||
|
||||
FIRActionCodeSettings *settings = [[FIRActionCodeSettings alloc] init];
|
||||
NSDictionary *android = actionCodeSettings[@"android"];
|
||||
BOOL handleCodeInApp = actionCodeSettings[@"handleCodeInApp"];
|
||||
NSDictionary *ios = actionCodeSettings[@"iOS"];
|
||||
NSString *url = actionCodeSettings[@"url"];
|
||||
|
||||
if (android) {
|
||||
BOOL installApp = android[@"installApp"];
|
||||
NSString *minimumVersion = android[@"minimumVersion"];
|
||||
NSString *packageName = android[@"packageName"];
|
||||
NSString *packageName = android[keyPackageName];
|
||||
NSString *minimumVersion = android[keyMinVersion];
|
||||
BOOL installApp = [android[keyInstallApp] boolValue];
|
||||
|
||||
[settings setAndroidPackageName:packageName installIfNotAvailable:installApp minimumVersion:minimumVersion];
|
||||
}
|
||||
|
||||
if (handleCodeInApp) {
|
||||
[settings setHandleCodeInApp:handleCodeInApp];
|
||||
}
|
||||
if (ios && ios[@"bundleId"]) {
|
||||
[settings setIOSBundleID:ios[@"bundleId"]];
|
||||
|
||||
if (ios && ios[keyBundleId]) {
|
||||
[settings setIOSBundleID:ios[keyBundleId]];
|
||||
}
|
||||
|
||||
if (url) {
|
||||
[settings setURL:[NSURL URLWithString:url]];
|
||||
}
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
|
||||
@@ -116,31 +116,30 @@ export default class User {
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Deprecated linkWithCredential in favor of linkAndRetrieveDataWithCredential.
|
||||
* @param credential
|
||||
*/
|
||||
linkWithCredential(credential: AuthCredential): Promise<User> {
|
||||
console.warn(
|
||||
'Deprecated firebase.User.prototype.linkWithCredential in favor of firebase.User.prototype.linkAndRetrieveDataWithCredential.'
|
||||
);
|
||||
linkWithCredential(credential: AuthCredential): Promise<UserCredential> {
|
||||
return getNativeModule(this._auth)
|
||||
.linkWithCredential(
|
||||
credential.providerId,
|
||||
credential.token,
|
||||
credential.secret
|
||||
)
|
||||
.then(user => this._auth._setUser(user));
|
||||
.then(userCredential => this._auth._setUserCredential(userCredential));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @deprecated Deprecated linkAndRetrieveDataWithCredential in favor of linkWithCredential.
|
||||
* @param credential
|
||||
*/
|
||||
linkAndRetrieveDataWithCredential(
|
||||
credential: AuthCredential
|
||||
): Promise<UserCredential> {
|
||||
console.warn(
|
||||
'Deprecated linkAndRetrieveDataWithCredential in favor of linkWithCredential.'
|
||||
);
|
||||
return getNativeModule(this._auth)
|
||||
.linkAndRetrieveDataWithCredential(
|
||||
.linkWithCredential(
|
||||
credential.providerId,
|
||||
credential.token,
|
||||
credential.secret
|
||||
@@ -152,30 +151,32 @@ export default class User {
|
||||
* Re-authenticate a user with a third-party authentication provider
|
||||
* @return {Promise} A promise resolved upon completion
|
||||
*/
|
||||
reauthenticateWithCredential(credential: AuthCredential): Promise<void> {
|
||||
console.warn(
|
||||
'Deprecated firebase.User.prototype.reauthenticateWithCredential in favor of firebase.User.prototype.reauthenticateAndRetrieveDataWithCredential.'
|
||||
);
|
||||
reauthenticateWithCredential(
|
||||
credential: AuthCredential
|
||||
): Promise<UserCredential> {
|
||||
return getNativeModule(this._auth)
|
||||
.reauthenticateWithCredential(
|
||||
credential.providerId,
|
||||
credential.token,
|
||||
credential.secret
|
||||
)
|
||||
.then(user => {
|
||||
this._auth._setUser(user);
|
||||
});
|
||||
.then(userCredential => this._auth._setUserCredential(userCredential));
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-authenticate a user with a third-party authentication provider
|
||||
*
|
||||
* @deprecated Deprecated reauthenticateAndRetrieveDataWithCredential in favor of reauthenticateWithCredential.
|
||||
* @return {Promise} A promise resolved upon completion
|
||||
*/
|
||||
reauthenticateAndRetrieveDataWithCredential(
|
||||
credential: AuthCredential
|
||||
): Promise<UserCredential> {
|
||||
console.warn(
|
||||
'Deprecated reauthenticateAndRetrieveDataWithCredential in favor of reauthenticateWithCredential..'
|
||||
);
|
||||
return getNativeModule(this._auth)
|
||||
.reauthenticateAndRetrieveDataWithCredential(
|
||||
.reauthenticateWithCredential(
|
||||
credential.providerId,
|
||||
credential.token,
|
||||
credential.secret
|
||||
|
||||
@@ -209,31 +209,33 @@ export default class Auth extends ModuleBase {
|
||||
|
||||
/**
|
||||
* Sign a user in anonymously
|
||||
* @deprecated Deprecated signInAnonymously in favor of signInAnonymouslyAndRetrieveData.
|
||||
*
|
||||
* @return {Promise} A promise resolved upon completion
|
||||
*/
|
||||
signInAnonymously(): Promise<User> {
|
||||
console.warn(
|
||||
'Deprecated firebase.User.prototype.signInAnonymously in favor of firebase.User.prototype.signInAnonymouslyAndRetrieveData.'
|
||||
);
|
||||
signInAnonymously(): Promise<UserCredential> {
|
||||
return getNativeModule(this)
|
||||
.signInAnonymously()
|
||||
.then(user => this._setUser(user));
|
||||
.then(userCredential => this._setUserCredential(userCredential));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sign a user in anonymously
|
||||
*
|
||||
* @deprecated Deprecated signInAnonymouslyAndRetrieveData in favor of signInAnonymously.
|
||||
* @return {Promise} A promise resolved upon completion
|
||||
*/
|
||||
signInAnonymouslyAndRetrieveData(): Promise<UserCredential> {
|
||||
console.warn(
|
||||
'Deprecated signInAnonymouslyAndRetrieveData in favor of signInAnonymously.'
|
||||
);
|
||||
return getNativeModule(this)
|
||||
.signInAnonymouslyAndRetrieveData()
|
||||
.signInAnonymously()
|
||||
.then(userCredential => this._setUserCredential(userCredential));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a user with the email/password functionality
|
||||
* @deprecated Deprecated createUserWithEmailAndPassword in favor of createUserAndRetrieveDataWithEmailAndPassword.
|
||||
*
|
||||
* @param {string} email The user's email
|
||||
* @param {string} password The user's password
|
||||
* @return {Promise} A promise indicating the completion
|
||||
@@ -241,17 +243,16 @@ export default class Auth extends ModuleBase {
|
||||
createUserWithEmailAndPassword(
|
||||
email: string,
|
||||
password: string
|
||||
): Promise<User> {
|
||||
console.warn(
|
||||
'Deprecated firebase.User.prototype.createUserWithEmailAndPassword in favor of firebase.User.prototype.createUserAndRetrieveDataWithEmailAndPassword.'
|
||||
);
|
||||
): Promise<UserCredential> {
|
||||
return getNativeModule(this)
|
||||
.createUserWithEmailAndPassword(email, password)
|
||||
.then(user => this._setUser(user));
|
||||
.then(userCredential => this._setUserCredential(userCredential));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a user with the email/password functionality
|
||||
*
|
||||
* @deprecated Deprecated createUserAndRetrieveDataWithEmailAndPassword in favor of createUserWithEmailAndPassword.
|
||||
* @param {string} email The user's email
|
||||
* @param {string} password The user's password
|
||||
* @return {Promise} A promise indicating the completion
|
||||
@@ -260,29 +261,34 @@ export default class Auth extends ModuleBase {
|
||||
email: string,
|
||||
password: string
|
||||
): Promise<UserCredential> {
|
||||
console.warn(
|
||||
'Deprecated createUserAndRetrieveDataWithEmailAndPassword in favor of createUserWithEmailAndPassword.'
|
||||
);
|
||||
return getNativeModule(this)
|
||||
.createUserAndRetrieveDataWithEmailAndPassword(email, password)
|
||||
.createUserWithEmailAndPassword(email, password)
|
||||
.then(userCredential => this._setUserCredential(userCredential));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sign a user in with email/password
|
||||
* @deprecated Deprecated signInWithEmailAndPassword in favor of signInAndRetrieveDataWithEmailAndPassword
|
||||
*
|
||||
* @param {string} email The user's email
|
||||
* @param {string} password The user's password
|
||||
* @return {Promise} A promise that is resolved upon completion
|
||||
*/
|
||||
signInWithEmailAndPassword(email: string, password: string): Promise<User> {
|
||||
console.warn(
|
||||
'Deprecated firebase.User.prototype.signInWithEmailAndPassword in favor of firebase.User.prototype.signInAndRetrieveDataWithEmailAndPassword.'
|
||||
);
|
||||
signInWithEmailAndPassword(
|
||||
email: string,
|
||||
password: string
|
||||
): Promise<UserCredential> {
|
||||
return getNativeModule(this)
|
||||
.signInWithEmailAndPassword(email, password)
|
||||
.then(user => this._setUser(user));
|
||||
.then(userCredential => this._setUserCredential(userCredential));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sign a user in with email/password
|
||||
*
|
||||
* @deprecated Deprecated signInAndRetrieveDataWithEmailAndPassword in favor of signInWithEmailAndPassword
|
||||
* @param {string} email The user's email
|
||||
* @param {string} password The user's password
|
||||
* @return {Promise} A promise that is resolved upon completion
|
||||
@@ -291,66 +297,73 @@ export default class Auth extends ModuleBase {
|
||||
email: string,
|
||||
password: string
|
||||
): Promise<UserCredential> {
|
||||
console.warn(
|
||||
'Deprecated signInAndRetrieveDataWithEmailAndPassword in favor of signInWithEmailAndPassword.'
|
||||
);
|
||||
return getNativeModule(this)
|
||||
.signInAndRetrieveDataWithEmailAndPassword(email, password)
|
||||
.signInWithEmailAndPassword(email, password)
|
||||
.then(userCredential => this._setUserCredential(userCredential));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sign the user in with a custom auth token
|
||||
* @deprecated Deprecated signInWithCustomToken in favor of signInAndRetrieveDataWithCustomToken
|
||||
*
|
||||
* @param {string} customToken A self-signed custom auth token.
|
||||
* @return {Promise} A promise resolved upon completion
|
||||
*/
|
||||
signInWithCustomToken(customToken: string): Promise<User> {
|
||||
console.warn(
|
||||
'Deprecated firebase.User.prototype.signInWithCustomToken in favor of firebase.User.prototype.signInAndRetrieveDataWithCustomToken.'
|
||||
);
|
||||
signInWithCustomToken(customToken: string): Promise<UserCredential> {
|
||||
return getNativeModule(this)
|
||||
.signInWithCustomToken(customToken)
|
||||
.then(user => this._setUser(user));
|
||||
.then(userCredential => this._setUserCredential(userCredential));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sign the user in with a custom auth token
|
||||
*
|
||||
* @deprecated Deprecated signInAndRetrieveDataWithCustomToken in favor of signInWithCustomToken
|
||||
* @param {string} customToken A self-signed custom auth token.
|
||||
* @return {Promise} A promise resolved upon completion
|
||||
*/
|
||||
signInAndRetrieveDataWithCustomToken(
|
||||
customToken: string
|
||||
): Promise<UserCredential> {
|
||||
console.warn(
|
||||
'Deprecated signInAndRetrieveDataWithCustomToken in favor of signInWithCustomToken.'
|
||||
);
|
||||
return getNativeModule(this)
|
||||
.signInAndRetrieveDataWithCustomToken(customToken)
|
||||
.signInWithCustomToken(customToken)
|
||||
.then(userCredential => this._setUserCredential(userCredential));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sign the user in with a third-party authentication provider
|
||||
* @deprecated Deprecated signInWithCredential in favor of signInAndRetrieveDataWithCredential.
|
||||
*
|
||||
* @return {Promise} A promise resolved upon completion
|
||||
*/
|
||||
signInWithCredential(credential: AuthCredential): Promise<User> {
|
||||
console.warn(
|
||||
'Deprecated firebase.User.prototype.signInWithCredential in favor of firebase.User.prototype.signInAndRetrieveDataWithCredential.'
|
||||
);
|
||||
signInWithCredential(credential: AuthCredential): Promise<UserCredential> {
|
||||
return getNativeModule(this)
|
||||
.signInWithCredential(
|
||||
credential.providerId,
|
||||
credential.token,
|
||||
credential.secret
|
||||
)
|
||||
.then(user => this._setUser(user));
|
||||
.then(userCredential => this._setUserCredential(userCredential));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sign the user in with a third-party authentication provider
|
||||
*
|
||||
* @deprecated Deprecated signInAndRetrieveDataWithCredential in favor of signInWithCredential.
|
||||
* @return {Promise} A promise resolved upon completion
|
||||
*/
|
||||
signInAndRetrieveDataWithCredential(
|
||||
credential: AuthCredential
|
||||
): Promise<UserCredential> {
|
||||
console.warn(
|
||||
'Deprecated signInAndRetrieveDataWithCredential in favor of signInWithCredential.'
|
||||
);
|
||||
return getNativeModule(this)
|
||||
.signInAndRetrieveDataWithCredential(
|
||||
.signInWithCredential(
|
||||
credential.providerId,
|
||||
credential.token,
|
||||
credential.secret
|
||||
|
||||
@@ -67,15 +67,16 @@ describe('auth()', () => {
|
||||
});
|
||||
});
|
||||
|
||||
xdescribe('signInWithCustomToken()', () => {
|
||||
describe('signInWithCustomToken()', () => {
|
||||
it('signs in with a admin sdk created custom auth token', async () => {
|
||||
const customUID = `custom${randomString(12, '#aA')}`;
|
||||
const token = await firebaseAdmin.auth().createCustomToken(customUID);
|
||||
const user = await firebase.auth().signInWithCustomToken(token);
|
||||
const { user } = await firebase.auth().signInWithCustomToken(token);
|
||||
user.uid.should.equal(customUID);
|
||||
firebase.auth().currentUser.uid.should.equal(customUID);
|
||||
|
||||
await firebase.auth().signOut();
|
||||
|
||||
const {
|
||||
user: user2,
|
||||
} = await firebase.auth().signInAndRetrieveDataWithCustomToken(token);
|
||||
@@ -87,7 +88,7 @@ describe('auth()', () => {
|
||||
|
||||
describe('onAuthStateChanged()', () => {
|
||||
it('calls callback with the current user and when auth state changes', async () => {
|
||||
await firebase.auth().signInAnonymouslyAndRetrieveData();
|
||||
await firebase.auth().signInAnonymously();
|
||||
|
||||
await sleep(50);
|
||||
|
||||
@@ -122,7 +123,7 @@ describe('auth()', () => {
|
||||
});
|
||||
|
||||
it('stops listening when unsubscribed', async () => {
|
||||
await firebase.auth().signInAnonymouslyAndRetrieveData();
|
||||
await firebase.auth().signInAnonymously();
|
||||
|
||||
// Test
|
||||
const callback = sinon.spy();
|
||||
@@ -169,7 +170,7 @@ describe('auth()', () => {
|
||||
|
||||
describe('onIdTokenChanged()', () => {
|
||||
it('calls callback with the current user and when auth state changes', async () => {
|
||||
await firebase.auth().signInAnonymouslyAndRetrieveData();
|
||||
await firebase.auth().signInAnonymously();
|
||||
|
||||
// Test
|
||||
const callback = sinon.spy();
|
||||
@@ -201,7 +202,7 @@ describe('auth()', () => {
|
||||
});
|
||||
|
||||
it('stops listening when unsubscribed', async () => {
|
||||
await firebase.auth().signInAnonymouslyAndRetrieveData();
|
||||
await firebase.auth().signInAnonymously();
|
||||
|
||||
// Test
|
||||
const callback = sinon.spy();
|
||||
@@ -247,7 +248,7 @@ describe('auth()', () => {
|
||||
|
||||
describe('onUserChanged()', () => {
|
||||
it('calls callback with the current user and when auth state changes', async () => {
|
||||
await firebase.auth().signInAnonymouslyAndRetrieveData();
|
||||
await firebase.auth().signInAnonymously();
|
||||
|
||||
// Test
|
||||
const callback = sinon.spy();
|
||||
@@ -283,7 +284,7 @@ describe('auth()', () => {
|
||||
});
|
||||
|
||||
it('stops listening when unsubscribed', async () => {
|
||||
await firebase.auth().signInAnonymouslyAndRetrieveData();
|
||||
await firebase.auth().signInAnonymously();
|
||||
|
||||
// Test
|
||||
const callback = sinon.spy();
|
||||
@@ -332,16 +333,19 @@ describe('auth()', () => {
|
||||
|
||||
describe('signInAnonymously()', () => {
|
||||
it('it should sign in anonymously', () => {
|
||||
const successCb = currentUser => {
|
||||
const successCb = currentUserCredential => {
|
||||
const currentUser = currentUserCredential.user;
|
||||
currentUser.should.be.an.Object();
|
||||
currentUser.uid.should.be.a.String();
|
||||
currentUser.toJSON().should.be.an.Object();
|
||||
should.equal(currentUser.toJSON().email, null);
|
||||
currentUser.isAnonymous.should.equal(true);
|
||||
currentUser.providerId.should.equal('firebase');
|
||||
|
||||
currentUser.should.equal(firebase.auth().currentUser);
|
||||
|
||||
const { additionalUserInfo } = currentUserCredential;
|
||||
additionalUserInfo.should.be.an.Object();
|
||||
|
||||
return firebase.auth().signOut();
|
||||
};
|
||||
|
||||
@@ -382,15 +386,20 @@ describe('auth()', () => {
|
||||
const email = 'test@test.com';
|
||||
const pass = 'test1234';
|
||||
|
||||
const successCb = currentUser => {
|
||||
const successCb = currentUserCredential => {
|
||||
const currentUser = currentUserCredential.user;
|
||||
currentUser.should.be.an.Object();
|
||||
currentUser.uid.should.be.a.String();
|
||||
currentUser.toJSON().should.be.an.Object();
|
||||
currentUser.toJSON().email.should.eql('test@test.com');
|
||||
currentUser.toJSON().email.should.eql(email);
|
||||
currentUser.isAnonymous.should.equal(false);
|
||||
currentUser.providerId.should.equal('firebase');
|
||||
currentUser.should.equal(firebase.auth().currentUser);
|
||||
|
||||
const { additionalUserInfo } = currentUserCredential;
|
||||
additionalUserInfo.should.be.an.Object();
|
||||
additionalUserInfo.isNewUser.should.equal(false);
|
||||
|
||||
return firebase.auth().signOut();
|
||||
};
|
||||
|
||||
@@ -563,7 +572,8 @@ describe('auth()', () => {
|
||||
'test1234'
|
||||
);
|
||||
|
||||
const successCb = currentUser => {
|
||||
const successCb = currentUserCredential => {
|
||||
const currentUser = currentUserCredential.user;
|
||||
currentUser.should.be.an.Object();
|
||||
currentUser.uid.should.be.a.String();
|
||||
currentUser.toJSON().should.be.an.Object();
|
||||
@@ -572,6 +582,10 @@ describe('auth()', () => {
|
||||
currentUser.providerId.should.equal('firebase');
|
||||
currentUser.should.equal(firebase.auth().currentUser);
|
||||
|
||||
const { additionalUserInfo } = currentUserCredential;
|
||||
additionalUserInfo.should.be.an.Object();
|
||||
additionalUserInfo.isNewUser.should.equal(false);
|
||||
|
||||
return firebase.auth().signOut();
|
||||
};
|
||||
|
||||
@@ -757,15 +771,17 @@ describe('auth()', () => {
|
||||
const email = `${random}@${random}.com`;
|
||||
const pass = random;
|
||||
|
||||
const successCb = newUser => {
|
||||
const successCb = newUserCredential => {
|
||||
const newUser = newUserCredential.user;
|
||||
newUser.uid.should.be.a.String();
|
||||
newUser.email.should.equal(email.toLowerCase());
|
||||
newUser.emailVerified.should.equal(false);
|
||||
newUser.isAnonymous.should.equal(false);
|
||||
newUser.providerId.should.equal('firebase');
|
||||
newUser.should.equal(firebase.auth().currentUser);
|
||||
newUser.metadata.should.be.an.Object();
|
||||
should.equal(newUser.phoneNumber, null);
|
||||
const { additionalUserInfo } = newUserCredential;
|
||||
additionalUserInfo.should.be.an.Object();
|
||||
additionalUserInfo.isNewUser.should.equal(true);
|
||||
|
||||
return newUser.delete();
|
||||
};
|
||||
@@ -1023,7 +1039,8 @@ describe('auth()', () => {
|
||||
const email = `${random}@${random}.com`;
|
||||
const pass = random;
|
||||
|
||||
const successCb = newUser => {
|
||||
const successCb = authResult => {
|
||||
const newUser = authResult.user;
|
||||
newUser.uid.should.be.a.String();
|
||||
newUser.email.should.equal(email.toLowerCase());
|
||||
newUser.emailVerified.should.equal(false);
|
||||
@@ -1094,7 +1111,7 @@ describe('auth()', () => {
|
||||
|
||||
await firebase
|
||||
.auth()
|
||||
.createUserAndRetrieveDataWithEmailAndPassword(email, pass);
|
||||
.createUserWithEmailAndPassword(email, pass);
|
||||
|
||||
try {
|
||||
await firebase.auth().sendPasswordResetEmail(email);
|
||||
|
||||
@@ -12,12 +12,12 @@ describe('auth().currentUser', () => {
|
||||
const email = `${random}@${random}.com`;
|
||||
const pass = random;
|
||||
|
||||
const newUser = await firebase
|
||||
const { user } = await firebase
|
||||
.auth()
|
||||
.createUserWithEmailAndPassword(email, pass);
|
||||
|
||||
// Test
|
||||
const token = await newUser.getIdToken();
|
||||
const token = await user.getIdToken();
|
||||
|
||||
// Assertions
|
||||
token.should.be.a.String();
|
||||
@@ -34,12 +34,12 @@ describe('auth().currentUser', () => {
|
||||
const email = `${random}@${random}.com`;
|
||||
const pass = random;
|
||||
|
||||
const newUser = await firebase
|
||||
const { user } = await firebase
|
||||
.auth()
|
||||
.createUserWithEmailAndPassword(email, pass);
|
||||
|
||||
// Test
|
||||
const token = await newUser.getToken();
|
||||
const token = await user.getToken();
|
||||
|
||||
// Assertions
|
||||
token.should.be.a.String();
|
||||
@@ -56,7 +56,7 @@ describe('auth().currentUser', () => {
|
||||
const email = `${random}@${random}.com`;
|
||||
const pass = random;
|
||||
|
||||
await firebase.auth().signInAnonymouslyAndRetrieveData();
|
||||
await firebase.auth().signInAnonymously();
|
||||
const currentUser = firebase.auth().currentUser;
|
||||
|
||||
// Test
|
||||
@@ -65,9 +65,12 @@ describe('auth().currentUser', () => {
|
||||
pass
|
||||
);
|
||||
|
||||
const linkedUser = await currentUser.linkWithCredential(credential);
|
||||
const linkedUserCredential = await currentUser.linkWithCredential(
|
||||
credential
|
||||
);
|
||||
|
||||
// Assertions
|
||||
const linkedUser = linkedUserCredential.user;
|
||||
linkedUser.should.be.an.Object();
|
||||
linkedUser.should.equal(firebase.auth().currentUser);
|
||||
linkedUser.email.toLowerCase().should.equal(email.toLowerCase());
|
||||
@@ -84,7 +87,7 @@ describe('auth().currentUser', () => {
|
||||
const email = 'test@test.com';
|
||||
const pass = 'test1234';
|
||||
|
||||
await firebase.auth().signInAnonymouslyAndRetrieveData();
|
||||
await firebase.auth().signInAnonymously();
|
||||
const currentUser = firebase.auth().currentUser;
|
||||
|
||||
// Test
|
||||
@@ -99,7 +102,7 @@ describe('auth().currentUser', () => {
|
||||
await firebase.auth().signOut();
|
||||
|
||||
// Reject
|
||||
Promise.reject(new Error('Did not error on link'));
|
||||
return Promise.reject(new Error('Did not error on link'));
|
||||
} catch (error) {
|
||||
// Assertions
|
||||
error.code.should.equal('auth/email-already-in-use');
|
||||
@@ -119,7 +122,7 @@ describe('auth().currentUser', () => {
|
||||
const email = `${random}@${random}.com`;
|
||||
const pass = random;
|
||||
|
||||
await firebase.auth().signInAnonymouslyAndRetrieveData();
|
||||
await firebase.auth().signInAnonymously();
|
||||
const currentUser = firebase.auth().currentUser;
|
||||
|
||||
// Test
|
||||
@@ -150,7 +153,7 @@ describe('auth().currentUser', () => {
|
||||
const email = 'test@test.com';
|
||||
const pass = 'test1234';
|
||||
|
||||
await firebase.auth().signInAnonymouslyAndRetrieveData();
|
||||
await firebase.auth().signInAnonymously();
|
||||
const currentUser = firebase.auth().currentUser;
|
||||
|
||||
// Test
|
||||
@@ -165,7 +168,7 @@ describe('auth().currentUser', () => {
|
||||
await firebase.auth().signOut();
|
||||
|
||||
// Reject
|
||||
Promise.reject(new Error('Did not error on link'));
|
||||
return Promise.reject(new Error('Did not error on link'));
|
||||
} catch (error) {
|
||||
// Assertions
|
||||
error.code.should.equal('auth/email-already-in-use');
|
||||
@@ -185,15 +188,14 @@ describe('auth().currentUser', () => {
|
||||
const email = `${random}@${random}.com`;
|
||||
const pass = random;
|
||||
|
||||
await firebase
|
||||
.auth()
|
||||
.createUserAndRetrieveDataWithEmailAndPassword(email, pass);
|
||||
await firebase.auth().createUserWithEmailAndPassword(email, pass);
|
||||
|
||||
// Test
|
||||
const credential = firebase.auth.EmailAuthProvider.credential(
|
||||
email,
|
||||
pass
|
||||
);
|
||||
|
||||
await firebase
|
||||
.auth()
|
||||
.currentUser.reauthenticateWithCredential(credential);
|
||||
@@ -222,6 +224,7 @@ describe('auth().currentUser', () => {
|
||||
email,
|
||||
pass
|
||||
);
|
||||
|
||||
await firebase
|
||||
.auth()
|
||||
.currentUser.reauthenticateAndRetrieveDataWithCredential(credential);
|
||||
@@ -237,7 +240,7 @@ describe('auth().currentUser', () => {
|
||||
|
||||
describe('reload()', () => {
|
||||
it('should not error', async () => {
|
||||
await firebase.auth().signInAnonymouslyAndRetrieveData();
|
||||
await firebase.auth().signInAnonymously();
|
||||
|
||||
try {
|
||||
await firebase.auth().currentUser.reload();
|
||||
@@ -245,7 +248,7 @@ describe('auth().currentUser', () => {
|
||||
} catch (error) {
|
||||
// Reject
|
||||
await firebase.auth().signOut();
|
||||
Promise.reject(new Error('reload() caused an error', error));
|
||||
return Promise.reject(new Error('reload() caused an error', error));
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -266,7 +269,7 @@ describe('auth().currentUser', () => {
|
||||
} catch (error) {
|
||||
// Reject
|
||||
await firebase.auth().currentUser.delete();
|
||||
Promise.reject(
|
||||
return Promise.reject(
|
||||
new Error('sendEmailVerification() caused an error', error)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"src/modules/admob**",
|
||||
"src/modules/auth/phone**",
|
||||
"src/modules/messaging**",
|
||||
"src/modules/notifications**",
|
||||
"src/types**",
|
||||
|
||||
Reference in New Issue
Block a user