메인 콘텐츠로 건너뛰기

Facebook 로그인 마이그레이션을 @capgo/social-login으로 진행하세요

개요

개요

이 가이드는 @capacitor-community/facebook-login 에서 @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.

  1. 기존 패키지를 제거하십시오.

    터미널 창
    npm uninstall @capacitor-community/facebook-login
  2. 새로운 패키지를 설치하십시오.

    터미널 창
    npm install @capgo/capacitor-social-login
    npx cap sync
import { FacebookLogin } from '@capacitor-community/facebook-login';
import { SocialLogin } from '@capgo/capacitor-social-login';

초기화

초기화란

키 변경code:에서 새로운 패키지는 명시적인 설정이 필요합니다.

// Old package required no explicit initialization in code
// Configuration was done only in native platforms
// New package requires explicit initialization
await 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'
}
});

응답 형식 변경

응답 형식 변경

새로운 프로필 객체 구조로 더 현대적인 응답 구조가 제공됩니다.:

// Old response type
interface FacebookLoginResponse {
accessToken: {
applicationId: string;
userId: string;
token: string;
expires: string;
};
recentlyGrantedPermissions: string[];
recentlyDeniedPermissions: string[];
}
// New response type
interface 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:

  • 응답에는 인증 제공자의 식별을 위한 필드가 포함되어 있습니다. provider 더 자세한
  • 추가 사용자 정보가 포함된 더 자세한 객체 profile 모든 사회 로그인 제공자에 걸쳐 일관된 구조
  • 로그인 상태 확인

로그인 상태 확인 섹션

클립보드에 복사
const result = await FacebookLogin.getCurrentAccessToken();
const isLoggedIn = result && result.accessToken;
const status = await SocialLogin.isLoggedIn({
provider: 'facebook'
});
const isLoggedIn = status.isLoggedIn;

__CAPGO_KEEP_0__

로그아웃
await FacebookLogin.logout();
await SocialLogin.logout({
provider: 'facebook'
});

플랫폼별 변경 사항

플랫폼별 변경 사항

Android 설정

Android 설정

initialize 메서드를 통해 구성이 처리됩니다.

// 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 인증을 위해 Client 토큰이 필요합니다.

iOS 설정

iOS 설정
  1. iOS 설정은 AppDelegate.swift 그대로 유지됩니다:
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]
)
  1. iOS 설정은 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>

iOS에서 변경 사항을 마이그레이션할 때 발생하는 변경 사항의 요약:

  1. explicit 초기화가 필요합니다 - 사용하기 전에 반드시 initialize() __CAPGO_KEEP_0__
  2. 응답 객체 구조가 크게 변경되었습니다. - 새로운 중첩된 결과 형식과 향상된 프로필 데이터
  3. 안드로이드용 클라이언트 토큰이 필요합니다. - 추가 구성이 필요합니다.
  4. 메서드 이름과 매개 변수 구조가 다릅니다. - 제공자 기반 접근 방식
  5. 에러 처리 및 에러 유형이 변경되었습니다. - 더 자세한 에러 정보

주요 이점

주요 이점

새로운 플러그인은 다음과 같습니다:

  • 통합 API 다양한 소셜 제공자 (Google, Apple, Facebook)across 중에
  • TypeScript 지원이 향상되었습니다. type 정의가 더 좋아졌습니다.
  • 프로필 데이터가 향상되었습니다. 사용자 정보가 더 많습니다.
  • 활발한 유지 관리 커뮤니티 지원
  • 모든 제공자에서 일관된 오류 처리 모든 제공자에서 일관된 오류 처리
  • 토큰 관리가 향상되었습니다. 만료 처리가 올바르게 처리되었습니다.

세부한 설정 지침에 대한 자세한 설명은 GitHub에 있습니다. 공식 문서.

페이스북 로그인 마이그레이션에서 계속하기 @capgo/social-login

페이스북 로그인 마이그레이션에서 계속하기 @capgo/social-login

Capgo를 사용 중이시면 페이스북 로그인 마이그레이션을 @capgo/social-login으로 인증 및 계정 흐름을 계획하고 연결하려면 @capgo/capacitor-social-login을 사용하세요. @capgo/capacitor-social-login의 네이티브 기능을 사용하기 위해 @capgo/capacitor-social-login @capgo/capacitor-social-login의 구현 세부 정보를 위해 @capgo/capacitor-passkey @capgo/capacitor-passkey의 구현 세부 정보를 위해 @capgo/capacitor-native-biometric implementation detail에 대한 @capgo/capacitor-native-biometric 두 단계 인증 implementation detail에 대한 두 단계 인증