Update authentication.md

This commit is contained in:
Michael Diarmid 2017-04-06 12:41:00 +01:00 committed by GitHub
parent eac406f007
commit 8c45b744c9
1 changed files with 37 additions and 0 deletions

View File

@ -284,3 +284,40 @@ firebase.auth().currentUser
.then()
.catch();
```
## Examples
### Facebook authentication with react-native-fbsdk and signInWithCredential
```javascript
import { AccessToken, LoginManager } from 'react-native-fbsdk';
// ... somewhere in your login screen component
LoginManager
.logInWithReadPermissions(['public_profile', 'email'])
.then((result) => {
if (result.isCancelled) {
return Promise.resolve('cancelled');
}
console.log(`Login success with permissions: ${result.grantedPermissions.toString()}`);
// get the access token
const data = AccessToken.getCurrentAccessToken();
// create a new firebase credential with the token
const credential = firebase.auth.FacebookAuthProvider.credential(data.accessToken);
// login with credential
return firebase.auth().signInWithCredential(credential);
})
.then((currentUser) => {
if (currentUser === 'cancelled') {
console.log('Login cancelled');
} else {
// now signed in
console.warn(JSON.stringify(currentUser.toJSON()));
}
})
.catch((error) => {
console.log(`Login fail with error: ${error}`);
});
```