From eae44231786b456aef30f341b46c444074bc45f9 Mon Sep 17 00:00:00 2001 From: Srijak Date: Sat, 25 Jun 2016 09:52:25 -0400 Subject: [PATCH 1/2] added support for signInWithCustomToken on ios --- firestack.ios.js | 9 +++++++++ ios/Firestack/Firestack.m | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/firestack.ios.js b/firestack.ios.js index be4b513..0cd6675 100644 --- a/firestack.ios.js +++ b/firestack.ios.js @@ -80,6 +80,15 @@ export default class Firestack { return promisify('signInWithProvider')(provider, authToken, authSecret); } + /** + * Sign the user in with a custom auth token + * @param {string} customToken A self-signed custom auth token. + * @return {Promise} A promise resolved upon completion + */ + signInWithCustomToken(customToken) { + return promisify('signInWithCustomToken')(customToken); + } + /** * Reauthenticate a user with a third-party authentication provider * @param {string} provider The provider name diff --git a/ios/Firestack/Firestack.m b/ios/Firestack/Firestack.m index fca5aed..4c55b1d 100644 --- a/ios/Firestack/Firestack.m +++ b/ios/Firestack/Firestack.m @@ -28,6 +28,27 @@ @implementation Firestack } } +RCT_EXPORT_METHOD(signInWithCustomToken: + (NSString *)customToken + callback:(RCTResponseSenderBlock) callback) +{ + [[FIRAuth auth] + signInWithCustomToken:customToken + completion:^(FIRUser *user, NSError *error) { + + if (user != nil) { + NSDictionary *userProps = [self userPropsFromFIRUser:user]; + callback(@[[NSNull null], userProps]); + } else { + NSDictionary *err = + [self handleFirebaseError:@"signinError" + error:error + withUser:user]; + callback(@[err]); + } + }]; +} + RCT_EXPORT_METHOD(signInWithProvider: (NSString *)provider token:(NSString *)authToken From 0e328fc0ed94f10097af778d7817e3560d350914 Mon Sep 17 00:00:00 2001 From: Srijak Date: Sat, 25 Jun 2016 09:56:42 -0400 Subject: [PATCH 2/2] updated README regarding signInWithCustomToken --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index 91284f6..f3c5658 100644 --- a/README.md +++ b/README.md @@ -166,6 +166,20 @@ server.signInWithEmail('ari@fullstack.io', '123456') }) ``` +#### signInWithCustomToken() + +To sign a user using a self-signed custom token, use the `signInWithCustomToken()` function. It accepts one parameter, the custom token: + +```javascript +server.signInWithCustomToken(TOKEN) + .then((user) => { + console.log('User successfully logged in', user) + }) + .catch((err) => { + console.error('User signin error', err); + }) +``` + #### signInWithProvider() We can use an external authentication provider, such as twitter/facebook for authentication. In order to use an external provider, we need to include another library to handle authentication.