iOS에서 Supabase Google 로그인
설치 단계와 이 플러그인의 전체 마크다운 가이드가 포함된 설정 프롬프트를 복사하세요.
이 가이드는 iOS에서 Google Sign-In을 Supabase 인증과 통합하는 방법을 설명합니다. Supabase 인증과 Google Sign-In을 통합하기 전에 다음을 완료한 것으로 가정합니다:
Implementation
Section titled “Implementation”구현은 예제 앱의 file supabaseAuthUtils.ts 에서 완전하게 제공됩니다. 이 가이드는 주요 개념과 사용 방법을 설명합니다.
인증 도우미 사용
Using the Authentication Helper그것은 authenticateWithGoogleSupabase 인증 흐름의 전체 처리를 담당하는 함수입니다.
import { authenticateWithGoogleSupabase } from './supabaseAuthUtils';
const result = await authenticateWithGoogleSupabase();if (result.success) { console.log('Signed in:', result.user); // Navigate to your authenticated area} else { console.error('Error:', result.error);}How It Works
contextHow It Works 인증 흐름이 어떻게 작동하는지 자세한 설명을 원하시면, nonce 생성, JWT 검증, Supabase 로그인과 같은 내용은 General Setup 가이드의.
How It Works
중요한 주의사항Section titled “iOS Token Caching and Nonce Issues”
iOS Token Caching and Nonce IssuesiOS Nonce Caching Issue
iOS에서 Google Sign-In은 토큰을 캐싱할 수 있습니다. 이는 nonce 검증이 실패하는 원인이 됩니다. validateJWTToken 이 함수는 이 문제를 자동으로 처리합니다.
- 자동 감지: 토큰에 포함된 nonce가 기대되는 nonce와 일치하는지 확인합니다.
nonceDigest - 자동 재시도: 검증이 실패하면 Google에서 자동으로 로그아웃하고 다시 시도합니다.
- 에러 처리: 재시도가 실패하면 에러를 반환합니다.
이게 왜 일어나는지: iOS Google Sign-In SDK caches tokens for performance. When a cached token is returned, it may have been generated with a different nonce (or no nonce), causing a mismatch.
해결 방법: Google 인증을 위해 자동으로 처리되며, 로그아웃하고 다시 시도하여 Google이 올바른 nonce를 포함한 새로운 토큰을 생성하도록 강제합니다.
수동 대안 (자동 재시도가 작동하지 않는 경우):
// Logout first to clear cached tokensawait SocialLogin.logout({ provider: 'google' });
// Then authenticateconst result = await authenticateWithGoogleSupabase();올바른 nonce가 포함된 새로운 토큰을 얻을 수 있도록 합니다.
완전한 code 참조를 보려면 General Setup 가이드의 "code 참조" 섹션을 참조하세요. Complete Code Reference section in the General Setup guide.
제목이 "중요한 주의 사항"인 섹션
nonce 처리제목이 "nonce 처리"인 섹션
nonce 처리 구현은 "nonce 처리" 섹션에서 설명한 패턴을 따릅니다.Nonce Handling React Native Google Sign In 문서:
rawNonceSupabase로 이동signInWithIdToken()- Supabase는 Google Sign-In의 ID 토큰에서 SHA-256 해시를 생성합니다.
rawNonceSupabase는 Google Sign-In의 ID 토큰에서 SHA-256 해시를 생성합니다.nonceDigestGoogle Sign-In의 ID 토큰에서 SHA-256 해시를 생성합니다. nonceDigestGoogle Sign-In API의 parameter로 이동nonce자동 재시도 메커니즘
자동 재시도 메커니즘
자동 재시도 메커니즘함수는 재시도 횟수를 포함합니다. authenticateWithGoogleSupabase parameter: retry 함수는 재시도 횟수를 포함합니다.
- 첫 번째 호출 (
retry=false: 유효성 검사 실패 시 자동 로그아웃하고 다시 시도합니다. - 재 호출 (
retry=true: 유효성 검사 실패 시 즉시 오류를 반환합니다.
이것은 iOS 토큰 캐싱 문제를 자동으로 처리합니다.
제목 '문제 해결'
- 인증이 실패하면:Nonce 일치하지 않음
- : 함수가 자동으로 다시 시도합니다. - 자세한 내용은 콘솔 로그를 확인하세요. 만약 지속되면 수동 로그아웃 먼저 해주세요.유효하지 않은 청중 (audience)입니다. : Google 클라이언트 ID가 Google Cloud Console과 Supabase (iOS 및 Web 클라이언트 ID 모두) 에서 일치하는지 확인하세요.
- 토큰 유효성 검사 실패: 올바른 idToken을 얻기 위해 initialize 호출에서 사용하는지 확인하세요
mode: 'online'Info.plist 구성 - : Info.plist에 올바른 URL schemes 및 GIDClientID가 있는지 확인하세요예시 앱 __CAPGO_KEEP_0__
- 참조 example app code 제목: Supabase Google Login on iOS에서 계속하기
Supabase Google Login on iOS를 사용 중인 경우
Supabase Google Login on iOS를 사용 중입니다Section titled “Keep going from Supabase Google Login on iOS” If you are using 인증 및 계정 흐름을 계획하고 연결하려면 Using @capgo/capacitor-social-login Using @capgo/capacitor-social-login Using @capgo/capacitor-social-login Using @capgo/capacitor-social-login Using @capgo/capacitor-passkey Using @capgo/capacitor-passkey Using @capgo/capacitor-native-biometric Using @capgo/capacitor-native-biometric Two-factor authentication Two-factor authentication