Skip to content

Conversation

@chriscanin
Copy link
Contributor

Description

This PR implements native Google Sign-In support for Expo iOS and Android apps using the @react-native-google-signin/google-signin library. This provides a seamless native authentication experience for users signing in with their Google accounts.

What's New

  • New Hook: useSignInWithGoogle() - Provides native Google Sign-In functionality for iOS and Android
    • Platform-specific implementations for iOS (useSignInWithGoogle.ios.ts) and Android (useSignInWithGoogle.android.ts)
    • Automatic handling of sign-in/sign-up transfer flow
    • Graceful error handling including user cancellation detection
    • Support for custom unsafeMetadata during authentication

Key Features

  • Native UI: Uses platform-native Google Sign-In UI instead of web-based OAuth flow
  • Automatic Flow Detection: Seamlessly handles both new user sign-up and existing user sign-in
  • Error Handling: Comprehensive error handling for:
    • Missing credentials
    • User cancellation (codes SIGN_IN_CANCELLED and -5)
    • Play Services availability (Android)
  • Environment Variable Support: Reads credentials from both Expo config and environment variables
  • Full Test Coverage: Complete unit tests with 100% coverage for the new hook

Files Changed

  • packages/expo/src/hooks/useSignInWithGoogle.ts - Cross-platform stub with helpful error message
  • packages/expo/src/hooks/useSignInWithGoogle.ios.ts - iOS-specific implementation
  • packages/expo/src/hooks/useSignInWithGoogle.android.ts - Android-specific implementation
  • packages/expo/src/hooks/__tests__/useSignInWithGoogle.test.ts - Comprehensive unit tests
  • packages/expo/src/hooks/index.ts - Export new hook
  • packages/expo/package.json - Add optional peer dependency
  • packages/expo/vitest.setup.mts - Add test mocks for expo-modules-core

Implementation Details

iOS Implementation:

  • Uses expo-apple-authentication for native Sign-In
  • Supports oauth_token_apple strategy
  • Handles identity token exchange

Android Implementation:

  • Uses @react-native-google-signin/google-signin library
  • Configures with Web Client ID and Android Client ID
  • Checks Google Play Services availability
  • Handles google_one_tap strategy with ID token

Both implementations:

  • Automatically handle transfer flow when user doesn't exist
  • Return consistent API: { createdSessionId, setActive, signIn, signUp }
  • Support optional unsafeMetadata parameter

Breaking Changes

None - this is a new feature.

Test Plan

  1. Unit tests pass (pnpm test --filter @clerk/clerk-expo)
  2. Build succeeds (pnpm build)
  3. All 9 test cases pass including:
    • Successful sign-in for existing users
    • Transfer flow for new users
    • User cancellation handling (both error codes)
    • Play Services availability check (Android)
    • Missing ID token validation
    • Missing credentials validation
    • Clerk not loaded handling

Documentation

Related documentation PR: [Link to clerk-docs PR]

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • JSDoc comments have been added for the new hook and all exported functions
  • Documentation has been created (see related PR in clerk-docs)

Type of change

  • 🌟 New feature

@chriscanin chriscanin self-assigned this Nov 12, 2025
@changeset-bot
Copy link

changeset-bot bot commented Nov 12, 2025

⚠️ No Changeset found

Latest commit: e8e1a67

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Nov 12, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
clerk-js-sandbox Ready Ready Preview Comment Nov 12, 2025 10:16pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 12, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chris/mobile-289-expo-google-universal-sign-in

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants