23 lines
1.1 KiB
JavaScript
23 lines
1.1 KiB
JavaScript
|
|
// 네이티브 Sign in with Apple 래퍼 (iOS 전용). 플러그인은 지연 import.
|
||
|
|
// 반환된 identity token(JWT)의 aud 는 앱 번들 ID → 백엔드 /api/auth/apple 가 JWKS 로 검증한다.
|
||
|
|
import { Capacitor } from '@capacitor/core'
|
||
|
|
|
||
|
|
// Apple 로그인은 iOS 네이티브에서만 노출한다(웹/안드로이드는 별도 흐름 필요 — 현재 미지원).
|
||
|
|
export function isNativeApple() {
|
||
|
|
return Capacitor.getPlatform() === 'ios'
|
||
|
|
}
|
||
|
|
|
||
|
|
// Sign in with Apple 수행 → { identityToken, name }.
|
||
|
|
// 이름(givenName/familyName)은 애플이 '최초 인증 시에만' 주므로 신규 가입 채움용으로 함께 반환.
|
||
|
|
export async function nativeAppleCredential() {
|
||
|
|
const { SignInWithApple } = await import('@capacitor-community/apple-sign-in')
|
||
|
|
const result = await SignInWithApple.authorize({
|
||
|
|
clientId: 'kr.sblog.slimbudget',
|
||
|
|
redirectURI: 'https://app.sblog.kr/auth/apple/callback',
|
||
|
|
scopes: 'email name',
|
||
|
|
})
|
||
|
|
const r = result?.response || {}
|
||
|
|
const name = [r.givenName, r.familyName].filter(Boolean).join(' ').trim() || null
|
||
|
|
return { identityToken: r.identityToken || null, name }
|
||
|
|
}
|