A Facebook Account Kit SDK wrapper for react-native (>= 0.19.0)
We strongly recommend you to use rnpm
that automatically installs the module from npm and links their native dependencies (for Android and/or iOS) with just one command:
rnpm link react-native-facebook-account-kit
Anyway, you can do it manually following the steps described below:
First, install the module from npm
npm install react-native-facebook-account-kit --save
If you are using Cocoapods add the following line to your Podfile
pod 'RNAccountKit', :path => '../node_modules/react-native-facebook-account-kit'
If you are not using Cocoapods:
- Open your project in XCode, right click on
Libraries
and clickAdd Files to "Your Project Name"
Look undernode_modules/react-native-facebook-account-kit
and addRNAccountKit.xcodeproj
. - Add
libRNAccountKit.a
toBuild Phases -> Link Binary With Libraries
.
-
In
android/settings.gradle
... include ':react-native-facebook-account-kit' project(':react-native-facebook-account-kit').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-facebook-account-kit/android')
-
In
android/app/build.gradle
add:dependencies { ... compile project(':react-native-facebook-account-kit') }
-
And finally, in
android/src/main/java/com/{YOUR_APP_NAME}/MainActivity.java
add://... import io.underscope.react.RNAccountKit; // <--- This! //... @Override protected List<ReactPackage> getPackages() { return Arrays.<ReactPackage>asList( new MainReactPackage(), new RNAccountKit() // <---- and This! );
}
### Usage
```javascript
import RNAccountKit from 'react-native-facebook-account-kit'
// Shows the Facebook Account Kit view for login via SMS
RNAccountKit.loginWithPhone()
.then((token) => {
console.log(`Logged with phone. Token: ${token}`)
})
// Shows the Facebook Account Kit view for login via email
RNAccountKit.loginWithEmail()
.then((token) => {
console.log(`Logged with email. Token: ${token}`)
})
// Logouts the user, so getCurrentAccessToken() will retrieve null
RNAccountKit.logout()
.then(() => {
console.log('Logged out')
})
// Retrieves the logged user access token, if any user is logged
RNAccountKit.getCurrentAccessToken()
.then((token) => {
console.log(`Current access token: ${token}`)
})
// Retrieves the logged user account info, if any user is logged
RNAccountKit.getCurrentAccount()
.then((account) => {
console.log(`Current account: ${account}`)
})
// Configures the SDK with some options
RNAccountKit.configure({
responseType: 'token'|'code' // 'token' by default,
titleType: 'login',
initialAuthState: '',
facebookNotificationsEnabled: true|false, // true by default
readPhoneStateEnabled: true|false, // true by default,
receiveSMS: true|false, // true by default,
SMSBlacklist: ['US'], // [] by default
SMSWhitelist: ['AR'] // [] by default
})
See the sample
License is MIT