From 05a7607aca6e1b5668843264d998b72aa382137d Mon Sep 17 00:00:00 2001 From: ChrisCanin Date: Thu, 16 Oct 2025 09:53:26 -0700 Subject: [PATCH 01/36] feat: add Apple Sign-In support with useAppleSignIn hook - Introduced `useAppleSignIn` hook for native Apple Sign-In on iOS using expo-apple-authentication. - Implemented flow to handle sign-in and sign-up using Clerk's backend. - Added type definitions for parameters and return types of the hook. - Updated `pnpm-lock.yaml` to include expo-apple-authentication as a dependency. - Modified strategies.ts to include 'oauth_token_apple' strategy type. --- packages/expo/package.json | 5 + packages/expo/src/hooks/index.ts | 1 + packages/expo/src/hooks/useAppleSignIn.ts | 156 ++ packages/types/src/signInCommon.ts | 5 + packages/types/src/signUpCommon.ts | 2 + packages/types/src/strategies.ts | 1 + pnpm-lock.yaml | 2000 +++++++++++---------- 7 files changed, 1182 insertions(+), 988 deletions(-) create mode 100644 packages/expo/src/hooks/useAppleSignIn.ts diff --git a/packages/expo/package.json b/packages/expo/package.json index 6b1d315ea43..917f67c1572 100644 --- a/packages/expo/package.json +++ b/packages/expo/package.json @@ -94,6 +94,7 @@ "devDependencies": { "@clerk/expo-passkeys": "workspace:*", "@types/base-64": "^1.0.2", + "expo-apple-authentication": "^7.2.4", "expo-auth-session": "^5.4.0", "expo-local-authentication": "^13.8.0", "expo-secure-store": "^12.8.1", @@ -102,6 +103,7 @@ }, "peerDependencies": { "@clerk/expo-passkeys": ">=0.0.6", + "expo-apple-authentication": ">=7.0.0", "expo-auth-session": ">=5", "expo-local-authentication": ">=13.5.0", "expo-secure-store": ">=12.4.0", @@ -114,6 +116,9 @@ "@clerk/expo-passkeys": { "optional": true }, + "expo-apple-authentication": { + "optional": true + }, "expo-local-authentication": { "optional": true }, diff --git a/packages/expo/src/hooks/index.ts b/packages/expo/src/hooks/index.ts index 40ceb2d56f7..4db6617468e 100644 --- a/packages/expo/src/hooks/index.ts +++ b/packages/expo/src/hooks/index.ts @@ -11,6 +11,7 @@ export { useReverification, } from '@clerk/clerk-react'; +export * from './useAppleSignIn'; export * from './useSSO'; export * from './useOAuth'; export * from './useAuth'; diff --git a/packages/expo/src/hooks/useAppleSignIn.ts b/packages/expo/src/hooks/useAppleSignIn.ts new file mode 100644 index 00000000000..915972e20fc --- /dev/null +++ b/packages/expo/src/hooks/useAppleSignIn.ts @@ -0,0 +1,156 @@ +import { useSignIn, useSignUp } from '@clerk/clerk-react'; +import type { SetActive, SignInResource, SignUpResource } from '@clerk/types'; +import * as AppleAuthentication from 'expo-apple-authentication'; +import { Platform } from 'react-native'; + +import { errorThrower } from '../utils/errors'; + +export type StartAppleSignInFlowParams = { + unsafeMetadata?: SignUpUnsafeMetadata; +}; + +export type StartAppleSignInFlowReturnType = { + createdSessionId: string | null; + setActive?: SetActive; + signIn?: SignInResource; + signUp?: SignUpResource; +}; + +/** + * Hook for native Apple Sign-In on iOS using expo-apple-authentication. + * + * This hook provides a simplified way to authenticate users with their Apple ID + * using the native iOS Sign in with Apple UI. The authentication flow automatically + * handles the ID token exchange with Clerk's backend and manages the transfer flow + * between sign-in and sign-up. + * + * @example + * ```tsx + * import { useAppleSignIn } from '@clerk/clerk-expo'; + * import { Button } from 'react-native'; + * + * function AppleSignInButton() { + * const { startAppleSignInFlow } = useAppleSignIn(); + * + * const onPress = async () => { + * try { + * const { createdSessionId, setActive } = await startAppleSignInFlow(); + * + * if (createdSessionId && setActive) { + * await setActive({ session: createdSessionId }); + * } + * } catch (err) { + * console.error('Apple Sign-In error:', err); + * } + * }; + * + * return