Facebook @capgo/social-login으로 로그인 마이그레이션
이 가이드는 @capacitor-community/facebook-login에서 @capgo/capacitor-social-login로 마이그레이션하기 위한 포괄적인 지침을 제공합니다. 새로운 플러그인은 여러 소셜 공급자, 향상된 TypeScript 지원 및 향상된 기능을 지원하는 통합 API을 통해 Facebook 인증을 현대화합니다.
-
기존 패키지를 제거합니다.
Terminal window npm uninstall @capacitor-community/facebook-login -
새 패키지를 설치합니다.
Terminal window npm install @capgo/capacitor-social-loginnpx cap sync
변경사항 가져오기
Section titled “변경사항 가져오기”import { FacebookLogin } from '@capacitor-community/facebook-login';import { SocialLogin } from '@capgo/capacitor-social-login';주요 변경 사항: 새 패키지를 사용하려면 코드에 명시적인 설정이 필요합니다.
// 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 }});이제 로그인 메소드는 공급자 매개변수를 허용합니다:
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' }});응답 유형 변경
Section titled “응답 유형 변경”응답 구조는 보다 포괄적인 프로필 객체로 현대화되었습니다.
// 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; }; };}주요 차이점:
- 이제 응답에는 인증 공급자를 식별하는
provider필드가 포함됩니다. - 추가 사용자 정보가 포함된 더 자세한
profile개체 - 모든 소셜 로그인 공급자의 일관된 구조
로그인 상태 확인하기
Section titled “로그인 상태 확인하기”const result = await FacebookLogin.getCurrentAccessToken();const isLoggedIn = result && result.accessToken;
const status = await SocialLogin.isLoggedIn({ provider: 'facebook'});const isLoggedIn = status.isLoggedIn;await FacebookLogin.logout();
await SocialLogin.logout({ provider: 'facebook'});플랫폼별 변경 사항
Section titled “플랫폼별 변경 사항”Android 설정
Section titled “Android 설정”이제 초기화 메소드를 통해 구성이 처리됩니다.
// 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 }});중요: 이제 Android 인증에는 클라이언트 토큰이 필요합니다.
iOS 설정
Section titled “iOS 설정”AppDelegate.swift의 iOS 설정은 동일하게 유지됩니다.
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])Info.plist구성은 동일하게 유지됩니다.
<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>주요 변경 사항
Section titled “주요 변경 사항”마이그레이션 시 주요 변경 사항 요약:
- 이제 명시적 초기화가 필요합니다 - 사용하기 전에
initialize()을 호출해야 합니다. - 응답 객체 구조가 크게 변경되었습니다 - 향상된 프로필 데이터를 갖춘 새로운 중첩 결과 형식
- 이제 Android에 클라이언트 토큰이 필요합니다 - 추가 구성이 필요합니다.
- 다른 메소드 이름 및 매개변수 구조 - 제공자 기반 접근 방식
- 오류 처리 및 오류 유형이 변경되었습니다 - 자세한 오류 정보
새로운 플러그인은 다음을 제공합니다:
- 여러 소셜 제공자(Google, Apple, Facebook)에 걸쳐 통합된 API
- 더 나은 유형 정의로 향상된 TypeScript 지원
- 더 많은 사용자 정보로 향상된 프로필 데이터
- 적극적인 유지 관리 및 커뮤니티 지원
- 모든 공급자에 걸쳐 일관적인 오류 처리
- 적절한 만료 처리를 통한 더 나은 토큰 관리
자세한 설정 방법은 공식 문서를 참고하세요.