diff --git a/README.md b/README.md index 4ee668b..ae86ffd 100644 --- a/README.md +++ b/README.md @@ -250,6 +250,31 @@ authManager.authorizeWithCallbackURL('twitter', appUrl) }) ``` +### socialLogin with custom Library +If you don't want to use [react-native-oauth](https://github.com/fullstackreact/react-native-oauth), you can use other library such as [react-native-facebook-login](https://github.com/magus/react-native-facebook-login). + +```javascript +var {FBLogin, FBLoginManager} = require('react-native-facebook-login'); + +var Login = React.createClass({ + render: function() { + return ( + { + console.log(user) + }) + }} + /> + ); + } +}); +``` + If the `signInWithProvider()` method resolves correct and we have already set up our `listenForAuth()` method properly, it will fire and we'll have a logged in user through Firebase. ### reauthenticateWithCredentialForProvider() @@ -312,6 +337,16 @@ firestack.deleteUser() .catch(err => console.error('There was an error - Now you are trapped!')) ``` +#### getToken() + +If you want user's token, use `getToken()` method. + +```javascript +firestack.getToken() +.then(res => console.log(res.token)) +.catch(err => console.error('error')) +``` + #### signOut() To sign the current user out, use the `signOut()` method. It accepts no parameters diff --git a/firestack.ios.js b/firestack.ios.js index 9ad60c7..5a08aee 100644 --- a/firestack.ios.js +++ b/firestack.ios.js @@ -136,6 +136,13 @@ export default class Firestack { deleteUser() { return promisify('deleteUser')() } + /** + * get the token of current user + * @return {Promise} + */ + getToken() { + return promisify('getToken')() + } /** * Update the current user's profile diff --git a/ios/Firestack.xcodeproj/xcuserdata/Cheol.xcuserdatad/xcschemes/Firestack.xcscheme b/ios/Firestack.xcodeproj/xcuserdata/Cheol.xcuserdatad/xcschemes/Firestack.xcscheme new file mode 100644 index 0000000..2ff8406 --- /dev/null +++ b/ios/Firestack.xcodeproj/xcuserdata/Cheol.xcuserdatad/xcschemes/Firestack.xcscheme @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ios/Firestack.xcodeproj/xcuserdata/Cheol.xcuserdatad/xcschemes/xcschememanagement.plist b/ios/Firestack.xcodeproj/xcuserdata/Cheol.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..9294764 --- /dev/null +++ b/ios/Firestack.xcodeproj/xcuserdata/Cheol.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,22 @@ + + + + + SchemeUserState + + Firestack.xcscheme + + orderHint + 0 + + + SuppressBuildableAutocreation + + 58B511DA1A9E6C8500147676 + + primary + + + + + diff --git a/ios/Firestack.xcworkspace/xcuserdata/Cheol.xcuserdatad/UserInterfaceState.xcuserstate b/ios/Firestack.xcworkspace/xcuserdata/Cheol.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..127972b Binary files /dev/null and b/ios/Firestack.xcworkspace/xcuserdata/Cheol.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/ios/Firestack/Firestack.m b/ios/Firestack/Firestack.m index 38d17dd..3b6a1c8 100644 --- a/ios/Firestack/Firestack.m +++ b/ios/Firestack/Firestack.m @@ -326,6 +326,40 @@ @implementation Firestack }]; } +RCT_EXPORT_METHOD(getToken:(RCTResponseSenderBlock) callback) +{ + FIRUser *user = [FIRAuth auth].currentUser; + + [user getTokenWithCompletion:^(NSString *token, NSError *_Nullable error) { + if (error) { + NSDictionary *err = + [self handleFirebaseError:@"getTokenError" + error:error + withUser:user]; + callback(@[err]); + } else { + callback(@[[NSNull null], @{@"token": token}]); + } + }]; +} + +RCT_EXPORT_METHOD(getTokenWithCompletion:(RCTResponseSenderBlock) callback) +{ + FIRUser *user = [FIRAuth auth].currentUser; + + [user getTokenWithCompletion:^(NSString *token , NSError *_Nullable error) { + if (error) { + NSDictionary *err = + [self handleFirebaseError:@"deleteUserError" + error:error + withUser:user]; + callback(@[err]); + } else { + callback(@[[NSNull null], @{@"result": token}]); + } + }]; +} + RCT_EXPORT_METHOD(reauthenticateWithCredentialForProvider: (NSString *)provider token:(NSString *)authToken @@ -585,6 +619,11 @@ - (FIRAuthCredential *)getCredentialForProvider:(NSString *)provider if ([provider isEqualToString: @"twitter"]) { credential = [FIRTwitterAuthProvider credentialWithToken:authToken secret:authTokenSecret]; + } if ([provider isEqualToString: @"facebook"]) { + credential = [FIRFacebookAuthProvider credentialWithAccessToken:authToken]; + } if ([provider isEqualToString: @"google"]) { + credential = [FIRGoogleAuthProvider credentialWithIDToken:authToken + accessToken:authTokenSecret]; } else { NSLog(@"Provider not yet handled"); } diff --git a/ios/Pods/Pods.xcodeproj/xcuserdata/Cheol.xcuserdatad/xcschemes/Pods-Firestack.xcscheme b/ios/Pods/Pods.xcodeproj/xcuserdata/Cheol.xcuserdatad/xcschemes/Pods-Firestack.xcscheme new file mode 100644 index 0000000..e787dc6 --- /dev/null +++ b/ios/Pods/Pods.xcodeproj/xcuserdata/Cheol.xcuserdatad/xcschemes/Pods-Firestack.xcscheme @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ios/Pods/Pods.xcodeproj/xcuserdata/Cheol.xcuserdatad/xcschemes/xcschememanagement.plist b/ios/Pods/Pods.xcodeproj/xcuserdata/Cheol.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..a386de4 --- /dev/null +++ b/ios/Pods/Pods.xcodeproj/xcuserdata/Cheol.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,22 @@ + + + + + SchemeUserState + + Pods-Firestack.xcscheme + + orderHint + 1 + + + SuppressBuildableAutocreation + + 7EC314ECB2B8568E8C3AAE095E7F7E98 + + primary + + + + +