Skip to content

Commit 577599d

Browse files
authored
Merge pull request #5 from g6ling/master
add getToken
2 parents 3e159ee + 7489f3a commit 577599d

File tree

8 files changed

+285
-0
lines changed

8 files changed

+285
-0
lines changed

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,31 @@ authManager.authorizeWithCallbackURL('twitter', appUrl)
252252
})
253253
```
254254

255+
### socialLogin with custom Library
256+
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).
257+
258+
```javascript
259+
var {FBLogin, FBLoginManager} = require('react-native-facebook-login');
260+
261+
var Login = React.createClass({
262+
render: function() {
263+
return (
264+
<FBLogin
265+
onLogin={function(data){
266+
console.log("Logged in!");
267+
console.log(data);
268+
let token = data.credentials.token
269+
firestack.signInWithProvider('facebook', token, '') // facebook need only access token.
270+
.then((user)=>{
271+
console.log(user)
272+
})
273+
}}
274+
/>
275+
);
276+
}
277+
});
278+
```
279+
255280
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.
256281

257282
### reauthenticateWithCredentialForProvider()
@@ -314,6 +339,16 @@ firestack.deleteUser()
314339
.catch(err => console.error('There was an error - Now you are trapped!'))
315340
```
316341

342+
#### getToken()
343+
344+
If you want user's token, use `getToken()` method.
345+
346+
```javascript
347+
firestack.getToken()
348+
.then(res => console.log(res.token))
349+
.catch(err => console.error('error'))
350+
```
351+
317352
#### signOut()
318353

319354
To sign the current user out, use the `signOut()` method. It accepts no parameters

firestack.ios.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,13 @@ export class Firestack {
136136
deleteUser() {
137137
return promisify('deleteUser')()
138138
}
139+
/**
140+
* get the token of current user
141+
* @return {Promise}
142+
*/
143+
getToken() {
144+
return promisify('getToken')()
145+
}
139146

140147
/**
141148
* Update the current user's profile
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "0730"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "58B511DA1A9E6C8500147676"
18+
BuildableName = "libFirestack.a"
19+
BlueprintName = "Firestack"
20+
ReferencedContainer = "container:Firestack.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES">
30+
<Testables>
31+
</Testables>
32+
<AdditionalOptions>
33+
</AdditionalOptions>
34+
</TestAction>
35+
<LaunchAction
36+
buildConfiguration = "Debug"
37+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
38+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
39+
launchStyle = "0"
40+
useCustomWorkingDirectory = "NO"
41+
ignoresPersistentStateOnLaunch = "NO"
42+
debugDocumentVersioning = "YES"
43+
debugServiceExtension = "internal"
44+
allowLocationSimulation = "YES">
45+
<MacroExpansion>
46+
<BuildableReference
47+
BuildableIdentifier = "primary"
48+
BlueprintIdentifier = "58B511DA1A9E6C8500147676"
49+
BuildableName = "libFirestack.a"
50+
BlueprintName = "Firestack"
51+
ReferencedContainer = "container:Firestack.xcodeproj">
52+
</BuildableReference>
53+
</MacroExpansion>
54+
<AdditionalOptions>
55+
</AdditionalOptions>
56+
</LaunchAction>
57+
<ProfileAction
58+
buildConfiguration = "Release"
59+
shouldUseLaunchSchemeArgsEnv = "YES"
60+
savedToolIdentifier = ""
61+
useCustomWorkingDirectory = "NO"
62+
debugDocumentVersioning = "YES">
63+
<MacroExpansion>
64+
<BuildableReference
65+
BuildableIdentifier = "primary"
66+
BlueprintIdentifier = "58B511DA1A9E6C8500147676"
67+
BuildableName = "libFirestack.a"
68+
BlueprintName = "Firestack"
69+
ReferencedContainer = "container:Firestack.xcodeproj">
70+
</BuildableReference>
71+
</MacroExpansion>
72+
</ProfileAction>
73+
<AnalyzeAction
74+
buildConfiguration = "Debug">
75+
</AnalyzeAction>
76+
<ArchiveAction
77+
buildConfiguration = "Release"
78+
revealArchiveInOrganizer = "YES">
79+
</ArchiveAction>
80+
</Scheme>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>SchemeUserState</key>
6+
<dict>
7+
<key>Firestack.xcscheme</key>
8+
<dict>
9+
<key>orderHint</key>
10+
<integer>0</integer>
11+
</dict>
12+
</dict>
13+
<key>SuppressBuildableAutocreation</key>
14+
<dict>
15+
<key>58B511DA1A9E6C8500147676</key>
16+
<dict>
17+
<key>primary</key>
18+
<true/>
19+
</dict>
20+
</dict>
21+
</dict>
22+
</plist>

ios/Firestack/Firestack.m

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,40 @@ @implementation Firestack
335335
}];
336336
}
337337

338+
RCT_EXPORT_METHOD(getToken:(RCTResponseSenderBlock) callback)
339+
{
340+
FIRUser *user = [FIRAuth auth].currentUser;
341+
342+
[user getTokenWithCompletion:^(NSString *token, NSError *_Nullable error) {
343+
if (error) {
344+
NSDictionary *err =
345+
[self handleFirebaseError:@"getTokenError"
346+
error:error
347+
withUser:user];
348+
callback(@[err]);
349+
} else {
350+
callback(@[[NSNull null], @{@"token": token}]);
351+
}
352+
}];
353+
}
354+
355+
RCT_EXPORT_METHOD(getTokenWithCompletion:(RCTResponseSenderBlock) callback)
356+
{
357+
FIRUser *user = [FIRAuth auth].currentUser;
358+
359+
[user getTokenWithCompletion:^(NSString *token , NSError *_Nullable error) {
360+
if (error) {
361+
NSDictionary *err =
362+
[self handleFirebaseError:@"deleteUserError"
363+
error:error
364+
withUser:user];
365+
callback(@[err]);
366+
} else {
367+
callback(@[[NSNull null], @{@"result": token}]);
368+
}
369+
}];
370+
}
371+
338372
RCT_EXPORT_METHOD(reauthenticateWithCredentialForProvider:
339373
(NSString *)provider
340374
token:(NSString *)authToken
@@ -654,6 +688,11 @@ - (FIRAuthCredential *)getCredentialForProvider:(NSString *)provider
654688
if ([provider isEqualToString: @"twitter"]) {
655689
credential = [FIRTwitterAuthProvider credentialWithToken:authToken
656690
secret:authTokenSecret];
691+
} if ([provider isEqualToString: @"facebook"]) {
692+
credential = [FIRFacebookAuthProvider credentialWithAccessToken:authToken];
693+
} if ([provider isEqualToString: @"google"]) {
694+
credential = [FIRGoogleAuthProvider credentialWithIDToken:authToken
695+
accessToken:authTokenSecret];
657696
} else {
658697
NSLog(@"Provider not yet handled");
659698
}

ios/Pods/Pods.xcodeproj/xcuserdata/Cheol.xcuserdatad/xcschemes/Pods-Firestack.xcscheme

Lines changed: 80 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ios/Pods/Pods.xcodeproj/xcuserdata/Cheol.xcuserdatad/xcschemes/xcschememanagement.plist

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)