Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add getToken #5

Merged
merged 4 commits into from
Aug 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<FBLogin
onLogin={function(data){
console.log("Logged in!");
console.log(data);
let token = data.credentials.token
firestack.signInWithProvider('facebook', token, '') // facebook need only access token.
.then((user)=>{
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()
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions firestack.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "58B511DA1A9E6C8500147676"
BuildableName = "libFirestack.a"
BlueprintName = "Firestack"
ReferencedContainer = "container:Firestack.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "58B511DA1A9E6C8500147676"
BuildableName = "libFirestack.a"
BlueprintName = "Firestack"
ReferencedContainer = "container:Firestack.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "58B511DA1A9E6C8500147676"
BuildableName = "libFirestack.a"
BlueprintName = "Firestack"
ReferencedContainer = "container:Firestack.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>Firestack.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>58B511DA1A9E6C8500147676</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
Binary file not shown.
39 changes: 39 additions & 0 deletions ios/Firestack/Firestack.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.