Skip to content

v2.4.0-alpha03

Choose a tag to compare

@github-actions github-actions released this 03 Aug 18:15
· 18 commits to main since this release

What's Changed

New Contributors

Full Changelog: v2.4.0-alpha02...v2.4.0-alpha03

Facebook Auth Support

This release adds support for Facebook Login with Firebase authentication in Android and iOS using KMPAuth.

Usage Example

//Facebook button with icon
FacebookButtonUiContainer(
    onResult = { result -> /* handle FirebaseUser result or error */ },
    linkAccount = false
) {
    FacebookSignInButtonIconOnly(onClick = { this.onClick() })
}

//Icon Only Button
FacebookButtonUiContainer(
    modifier = Modifier.fillMaxWidth().height(44.dp),
    onResult = { result -> /* handle result */ },
    linkAccount = false
) {
    FacebookSignInButton(fontSize = 19.sp) { this.onClick() }
}

//Custom Button
FacebookButtonUiContainer(
    modifier = Modifier.fillMaxWidth().height(44.dp),
    onResult = { result -> /* handle result */ },
    linkAccount = false
) {
    //Your custom Button here
    YourCustomButton(fontSize = 19.sp) { this.onClick() }
}

Android Setup

Add these to your res/values/strings.xml:

<string name="facebook_app_id">YOUR_FACEBOOK_APP_ID</string>
<string name="fb_login_protocol_scheme">fbYOUR_FACEBOOK_APP_ID</string>
<string name="facebook_client_token">YOUR_FACEBOOK_CLIENT_TOKEN</string>

Add these metadata tags and Facebook Activity to your AndroidManifest.xml inside the <application> tag:

<meta-data
    android:name="com.facebook.sdk.ApplicationId"
    android:value="@string/facebook_app_id" />

<meta-data
    android:name="com.facebook.sdk.ClientToken"
    android:value="@string/facebook_client_token" />

<activity
    android:name="com.facebook.FacebookActivity"
    android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
    android:label="@string/app_name" />

For Facebook Login, on Your Main Activity's activity result call KMPAuth.handleFacebookActivityResult function:

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    KMPAuth.handleFacebookActivityResult(requestCode, resultCode, data)
    super.onActivityResult(requestCode, resultCode, data)
}

IOS Setup

Add Facebook Login SDK Swift Package, and add below to your Info.plist:

<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>fbFACEBOOK_APP_ID</string> <!-- Your Facebook App ID with 'fb' prefix -->
    </array>
  </dict>
</array>

<key>FacebookAppID</key>
<string>FACEBOOK_APP_ID</string>

<key>FacebookClientToken</key>
<string>YOUR_FACEBOOK_CLIENT_TOKEN</string>

<key>FacebookDisplayName</key>
<string>YourAppDisplayName</string>

<key>LSApplicationQueriesSchemes</key>
<array>
  <string>fbapi</string>
  <string>fb-messenger-api</string>
  <string>fbauth2</string>
  <string>fbshareextension</string>
</array>

Initialize Facebook SDK on Ios Swift side

func application(_ application: UIApplication,
                     didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
        FirebaseApp.configure()
        // Initialize Facebook SDK. 
        FBSDKCoreKit.ApplicationDelegate.shared.application(
            application,
            didFinishLaunchingWithOptions: launchOptions
        )
        return true
    }

func application(
    _ app: UIApplication,
    open url: URL,
    options: [UIApplication.OpenURLOptionsKey : Any] = [:]
) -> Bool {
    
    var handled: Bool
    handled = FBSDKCoreKit.ApplicationDelegate.shared.application(
        app,
        open: url,
        options: options
    )

    if handled {
        return true
    }
    
    return false
}

Notes