Skip to content

added support for signInWithCustomToken on ios. #2

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

Merged
merged 2 commits into from
Jun 27, 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
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,20 @@ server.signInWithEmail('[email protected]', '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.
Expand Down
9 changes: 9 additions & 0 deletions firestack.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions ios/Firestack/Firestack.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down