- Remove the old package:
npm uninstall @capacitor-community/apple-sign-in- Install the new package:
npm install @capgo/capacitor-social-login
npx cap sync- import { SignInWithApple } from '@capacitor-community/apple-sign-in';
+ import { SocialLogin } from '@capgo/capacitor-social-login';- // No initialization needed in old package
+ await SocialLogin.initialize({
+ apple: {} // Basic iOS configuration
+ });
+ // For Android, you need additional configuration:
+ await SocialLogin.initialize({
+ apple: {
+ clientId: 'YOUR_SERVICE_ID', // Service ID from Apple Developer Portal
+ redirectUrl: 'https://your-backend.com/callback' // Your backend callback URL. Please note that this URL behaves differently than in @capacitor-community/apple-sign-in. Please refer to the documentation for more details.
+ }
+ });- const result = await SignInWithApple.authorize({
- clientId: 'com.your.app',
- redirectURI: 'https://your-app.com/callback',
- scopes: 'email name',
- state: '12345',
- nonce: 'nonce'
- });
+ const result = await SocialLogin.login({
+ provider: 'apple',
+ options: {
+ // Optional: Add scopes if needed
+ scopes: ['email', 'name'],
+ nonce: 'nonce'
+ }
+ });The response object structure has changed. Here's how to handle the new response:
// Old response type
interface AppleSignInResponse {
response: {
user: string;
email: string | null;
givenName: string | null;
familyName: string | null;
identityToken: string | null;
authorizationCode: string | null;
};
}
// New response type
interface SocialLoginResponse {
provider: 'apple';
result: {
accessToken: {
token: string;
expiresIn?: number;
refreshToken?: string;
} | null;
idToken: string | null;
profile: {
user: string;
email: string | null;
givenName: string | null;
familyName: string | null;
};
};
}- // Not available in old package
+ const status = await SocialLogin.isLoggedIn({
+ provider: 'apple'
+ });- // Not available in old package
+ await SocialLogin.logout({
+ provider: 'apple'
+ });- The iOS setup remains largely the same. You still need to:
- Enable "Sign In with Apple" capability in Xcode
- Configure your app in the Apple Developer Portal
- No additional code changes required for iOS
The new plugin provides Android support out of the box, but requires additional setup:
- Create a Services ID in the Apple Developer Portal
- Configure a web authentication endpoint
- Set up your Android app to handle the OAuth flow
For detailed Android setup instructions, please refer to the Android Setup Guide.
The new plugin offers several advantages:
- Built-in Android support through web-based authentication
- Unified API for multiple social login providers (Google, Facebook)
- Persistent login state management
- TypeScript support with better type definitions
- Active maintenance and community support
- The initialization step is now required
- Response object structure has changed
- Android implementation requires a backend service
- Token refresh handling is different
- Error handling and error types have changed
For more detailed setup instructions, please refer to the official documentation.