Skip to content

Commit b5e71c6

Browse files
committed
Merge branch 'master' of github.com:fullstackreact/react-native-firestack
* 'master' of github.com:fullstackreact/react-native-firestack: Update README.md Update README.md updated README regarding signInWithCustomToken added support for signInWithCustomToken on ios
2 parents 6e223c8 + ebd1909 commit b5e71c6

File tree

3 files changed

+46
-10
lines changed

3 files changed

+46
-10
lines changed

README.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,6 @@ If you prefer not to use `rnpm`, we can manually link the package together with
5151

5252
![Recursive paths](http://d.pr/i/1hAr1.png)
5353

54-
#### Cocoapods
55-
56-
You can also install `Firestack` as a cocoapod by adding the line to your `ios/Podfile`
57-
58-
```ruby
59-
pod 'Firestack'
60-
```
61-
6254
### Android
6355

6456
Coming soon
@@ -166,6 +158,20 @@ server.signInWithEmail('ari@fullstack.io', '123456')
166158
})
167159
```
168160

161+
#### signInWithCustomToken()
162+
163+
To sign a user using a self-signed custom token, use the `signInWithCustomToken()` function. It accepts one parameter, the custom token:
164+
165+
```javascript
166+
server.signInWithCustomToken(TOKEN)
167+
.then((user) => {
168+
console.log('User successfully logged in', user)
169+
})
170+
.catch((err) => {
171+
console.error('User signin error', err);
172+
})
173+
```
174+
169175
#### signInWithProvider()
170176

171177
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.
@@ -199,7 +205,7 @@ Once the app is configured with the instructions, we can call the `oauthManager`
199205
const appUrl = 'app-uri://oauth-callback/twitter'
200206
authManager.authorizeWithCallbackURL('twitter', appUrl)
201207
.then(creds => {
202-
return server.signInWithProvider('twitter', creds.oauth_token creds.oauth_token_secret)
208+
return server.signInWithProvider('twitter', creds.oauth_token, creds.oauth_token_secret)
203209
.then(() => {
204210
// We're now signed in through Firebase
205211
})
@@ -370,7 +376,7 @@ server.storage.ref(photo.fullPath)
370376
The native Firebase JavaScript library provides a featureful realtime database that works out of the box. Firestack provides an attribute to interact with the database without needing to configure the JS library.
371377

372378
```javascript
373-
server.storage
379+
server.database
374380
.ref(LIST_KEY)
375381
.orderByChild('timestamp')
376382
.on('value', snapshot => {

firestack.ios.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ export default class Firestack {
8080
return promisify('signInWithProvider')(provider, authToken, authSecret);
8181
}
8282

83+
/**
84+
* Sign the user in with a custom auth token
85+
* @param {string} customToken A self-signed custom auth token.
86+
* @return {Promise} A promise resolved upon completion
87+
*/
88+
signInWithCustomToken(customToken) {
89+
return promisify('signInWithCustomToken')(customToken);
90+
}
91+
8392
/**
8493
* Reauthenticate a user with a third-party authentication provider
8594
* @param {string} provider The provider name

ios/Firestack/Firestack.m

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,27 @@ @implementation Firestack
2828
}
2929
}
3030

31+
RCT_EXPORT_METHOD(signInWithCustomToken:
32+
(NSString *)customToken
33+
callback:(RCTResponseSenderBlock) callback)
34+
{
35+
[[FIRAuth auth]
36+
signInWithCustomToken:customToken
37+
completion:^(FIRUser *user, NSError *error) {
38+
39+
if (user != nil) {
40+
NSDictionary *userProps = [self userPropsFromFIRUser:user];
41+
callback(@[[NSNull null], userProps]);
42+
} else {
43+
NSDictionary *err =
44+
[self handleFirebaseError:@"signinError"
45+
error:error
46+
withUser:user];
47+
callback(@[err]);
48+
}
49+
}];
50+
}
51+
3152
RCT_EXPORT_METHOD(signInWithProvider:
3253
(NSString *)provider
3354
token:(NSString *)authToken

0 commit comments

Comments
 (0)