feat(auth): 앱(네이티브) 구글 로그인 — @capgo/capacitor-social-login
CI / build (push) Failing after 12m48s

- 웹은 기존 GIS 유지, Capacitor 네이티브(APK)는 네이티브 구글 로그인 사용
  (웹뷰에서 GIS 팝업/FedCM 미동작 대응)
- 받은 ID 토큰은 기존과 동일하게 백엔드 /api/auth/google 로 검증
- src/lib/googleAuth.ts + LoginPage 네이티브/웹 분기

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
ByungCheol
2026-07-12 11:02:51 +09:00
parent a7b633a3e5
commit 7f18d18a11
4 changed files with 85 additions and 2 deletions
+35
View File
@@ -0,0 +1,35 @@
import { Capacitor } from '@capacitor/core'
import { SocialLogin } from '@capgo/capacitor-social-login'
/**
* 네이티브(Capacitor) 구글 로그인.
* 웹뷰에서는 GIS(팝업/FedCM)가 동작하지 않으므로, 앱에서는 이 네이티브 흐름을 사용한다.
* 받은 ID 토큰은 웹 GIS 와 동일하게 백엔드 /api/auth/google 로 검증한다.
*/
let initializedFor = ''
/** 네이티브 플랫폼(iOS/Android) 여부 — 웹은 기존 GIS 사용. */
export function isNativeGoogleAvailable(): boolean {
return Capacitor.isNativePlatform()
}
/**
* 네이티브 구글 로그인 → ID 토큰 반환.
* @param webClientId 백엔드가 aud 검증에 쓰는 웹 클라이언트 ID (serverClientId)
*/
export async function signInWithGoogle(webClientId: string): Promise<string> {
if (initializedFor !== webClientId) {
await SocialLogin.initialize({ google: { webClientId } })
initializedFor = webClientId
}
const res = await SocialLogin.login({
provider: 'google',
options: { scopes: ['email', 'profile'] },
})
const result = res.result as { idToken?: string | null }
if (!result?.idToken) {
throw new Error('구글 ID 토큰을 받지 못했습니다.')
}
return result.idToken
}