Update authentication.md
This commit is contained in:
parent
eac406f007
commit
8c45b744c9
@ -284,3 +284,40 @@ firebase.auth().currentUser
|
|||||||
.then()
|
.then()
|
||||||
.catch();
|
.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}`);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
Loading…
x
Reference in New Issue
Block a user