Migration Guide from @capacitor-community/facebook-login to @capgo/capacitor-social-login
Ce contenu n'est pas encore disponible dans votre langue.
Overview
This guide provides comprehensive instructions for migrating from @capacitor-community/facebook-login to @capgo/capacitor-social-login. The new plugin modernizes Facebook authentication with a unified API that supports multiple social providers, improved TypeScript support, and enhanced capabilities.
Installation
-
Remove the old package:
Terminal window npm uninstall @capacitor-community/facebook-login -
Install the new package:
Terminal window npm install @capgo/capacitor-social-loginnpx cap sync
Code Changes
Import Changes
import { FacebookLogin } from '@capacitor-community/facebook-login';import { SocialLogin } from '@capgo/capacitor-social-login';Initialization
Key Change: The new package requires explicit setup in your code:
// Old package required no explicit initialization in code// Configuration was done only in native platforms
// New package requires explicit initializationawait SocialLogin.initialize({ facebook: { appId: 'YOUR_FACEBOOK_APP_ID', // Required for web and Android clientToken: 'YOUR_CLIENT_TOKEN' // Required for Android }});Login
The login method now accepts a provider parameter:
const FACEBOOK_PERMISSIONS = ['email', 'public_profile'];const result = await FacebookLogin.login({ permissions: FACEBOOK_PERMISSIONS });
const result = await SocialLogin.login({ provider: 'facebook', options: { permissions: ['email', 'public_profile'], limitedLogin: false, nonce: 'optional_nonce' }});Response Type Changes
The response structure has been modernized with a more comprehensive profile object:
// Old response typeinterface FacebookLoginResponse { accessToken: { applicationId: string; userId: string; token: string; expires: string; }; recentlyGrantedPermissions: string[]; recentlyDeniedPermissions: string[];}
// New response typeinterface FacebookLoginResponse { provider: 'facebook'; result: { accessToken: { token: string; applicationId?: string; expires?: string; userId?: string; permissions?: string[]; declinedPermissions?: string[]; } | null; idToken: string | null; profile: { userID: string; email: string | null; friendIDs: string[]; birthday: string | null; ageRange: { min?: number; max?: number } | null; gender: string | null; location: { id: string; name: string } | null; hometown: { id: string; name: string } | null; profileURL: string | null; name: string | null; imageURL: string | null; }; };}Key Differences:
- Response now includes a
providerfield identifying the authentication provider - More detailed
profileobject with additional user information - Consistent structure across all social login providers
Checking Login Status
const result = await FacebookLogin.getCurrentAccessToken();const isLoggedIn = result && result.accessToken;
const status = await SocialLogin.isLoggedIn({ provider: 'facebook'});const isLoggedIn = status.isLoggedIn;Logout
await FacebookLogin.logout();
await SocialLogin.logout({ provider: 'facebook'});Platform Specific Changes
Android Setup
Configuration is now handled through the initialize method:
// AndroidManifest.xml changes remain the same// strings.xml become irrelevant// Additionally initialize in your code:await SocialLogin.initialize({ facebook: { appId: 'your-app-id', clientToken: 'your-client-token' // New requirement }});Important: Client token is now required for Android authentication.
iOS Setup
- The iOS setup in
AppDelegate.swiftremains the same:
import FBSDKCoreKit
// In application:didFinishLaunchingWithOptions:FBSDKCoreKit.ApplicationDelegate.shared.application( application, didFinishLaunchingWithOptions: launchOptions)
// In application:openURL:options:ApplicationDelegate.shared.application( app, open: url, sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String, annotation: options[UIApplication.OpenURLOptionsKey.annotation])- The
Info.plistconfiguration remains the same:
<key>CFBundleURLTypes</key><array> <dict> <key>CFBundleURLSchemes</key> <array> <string>fb[APP_ID]</string> </array> </dict></array><key>FacebookAppID</key><string>[APP_ID]</string><key>FacebookClientToken</key><string>[CLIENT_TOKEN]</string><key>FacebookDisplayName</key><string>[APP_NAME]</string><key>LSApplicationQueriesSchemes</key><array> <string>fbapi</string> <string>fbauth</string> <string>fb-messenger-share-api</string> <string>fbauth2</string> <string>fbshareextension</string></array>Breaking Changes
Summary of breaking changes when migrating:
- Explicit initialization is now required - Must call
initialize()before use - Response object structure has changed significantly - New nested result format with enhanced profile data
- Client token is now required for Android - Additional configuration needed
- Different method names and parameter structures - Provider-based approach
- Error handling and error types have changed - More detailed error information
Key Advantages
The new plugin provides:
- Unified API across multiple social providers (Google, Apple, Facebook)
- Improved TypeScript support with better type definitions
- Enhanced profile data with more user information
- Active maintenance and community support
- Consistent error handling across all providers
- Better token management with proper expiration handling
For more detailed setup instructions, please refer to the official documentation.