Passer au contenu

Supabase Apple Connexion on Web

This Guide will Aide you integrate Apple Sign-In with Supabase Authentication on Web. It is assumed that you have already completed:

The complete implementation is available in the example app’s supabaseAuthUtils.ts file. This guide explains the key concepts and how to use it.

The authenticateWithAppleSupabase function handles the entire authentication flow:

import { authenticateWithAppleSupabase } from './supabaseAuthUtils';
const result = await authenticateWithAppleSupabase();
if (result.success) {
console.log('Signed in:', result.user);
// Navigate to your authenticated area
} else {
console.error('Error:', result.error);
}

On Web, Apple Sign-In uses an OAuth popup flow:

  1. Initialisation: The plugin is initialized with your Service ID and the current page URL as the redirect URL
  2. OAuth Popup: Opens a popup window with Apple’s OAuth page
  3. Utilisateur Authentication: Utilisateur authenticates with Apple in the popup
  4. Identity Token: Apple Retourne an identity token (JWT) containing Utilisateur Information
  5. Supabase Authentication: The identity token is sent to Supabase using signInWithIdToken()

The helper function automatically detects the web platform and configures everything appropriately.

  • Web requires your Apple Service ID (same as Android)
  • The Service ID must be configured in Apple Developer Portal with the correct Return URLs
  • Make sure your domain is added to the allowed domains in Apple Developer Portal
  • On web, the redirect URL is automatically set to window.location.href (current page URL)
  • This must match one of the Return URLs configured in Apple Developer Portal
  • Ensure both the URL with and without trailing slash are configured in Apple Developer Portal

In Supabase, configure your Apple provider with:

  • Client ID: Your Apple Service ID (e.g., com.example.app.service)

If you’re also using iOS, you’ll need to provide both the Application ID and Service ID in Supabase’s Client ID field (comma-separated).

When using the authenticateWithAppleSupabase helper function, you must update the clientId to match your Apple Service ID:

await SocialLogin.initialize({
apple: {
clientId: isIOS
? undefined // iOS uses bundle ID automatically
: 'your.service.id.here', // Your Apple Service ID for Web and Android
redirectUrl: redirectUrl,
},
});

Important

Replace 'your.service.id.here' with your actual Apple Service ID (the same value you configured in Apple Developer Portal).

If authentication fails:

  • Service ID mismatch: Verify your Service ID matches in both Apple Developer Portal and your code
  • Return URL not configured: Ensure your current page URL (with and without trailing slash) is configured in Apple Developer Portal
  • Popup blocked: Vérifier browser Paramètres - some browsers block popups by default
  • Domain not allowed: Verify your domain is added to the allowed domains in Apple Developer Portal
  • Supabase Configuration: Verify your Service ID is correctly configured in Supabase Apple provider Paramètres
  • Review the Exemple Application code for Référence