Overview
Authentication is handled through:- Clerk SDK for session management
- JWT tokens for API authentication
- SecureStore for token persistence
- OAuth flows for social login
Authentication methods
Email/password
Traditional email and password authentication with:- Email verification
- Password reset flow
- Session management
Google OAuth
“Continue with Google” runsuseGoogleSsoFlow (lib/hooks/useGoogleSsoFlow.ts), which picks one of two flows:
A cancel in either flow returns quietly. Other failures show copy from
lib/errors/userFacingError.ts, never Clerk’s raw text. The native module ships only in a new store build; it cannot go out over the air.
Native Google sign-in configuration
The client IDs are public identifiers, not secrets. They come from the EAS environment (or a local.env), never from the repo. app.config.js copies them into extra, where Clerk’s hook and config plugin read them, and appends .apps.googleusercontent.com to a client ID given without it. Without them the app uses the browser flow and never touches the native module.
The URL scheme gate matters because GoogleSignIn on iOS raises a native exception, which JavaScript cannot catch, when the reversed client ID scheme is missing from the app.
1
Google Cloud
- A Web application OAuth client. Its ID and secret are the custom credentials on Clerk’s Google connection.
- An iOS OAuth client for bundle ID
com.soundchecklive.app(with the Apple Team ID). - An Android OAuth client for package
com.soundchecklive.appwith the SHA-1 of the EAS upload keystore (eas credentials -p android). Builds installed from Google Play are re-signed, so add a second Android client with the SHA-1 of the Play app signing key (Play Console → App integrity). A new Android client can take a few hours to start working; until then the app falls back to the browser.
2
Clerk dashboard (each instance used by dev, qa and prod builds)
- SSO connections → Google: enabled, with custom credentials (the web client ID and secret from step 1).
- Native applications: register the iOS app (Team ID + bundle ID) and the Android app (package name + SHA-256 fingerprints of the upload and Play signing keys).
- Keep
soundcheck://oauth-callbackin the allowed redirect URLs so the browser fallback keeps working.
3
EAS environment variables
Set the variables in the table above (plain-text visibility), each matching the Clerk instance behind that environment’s publishable key. Then make a new native build.
Apple sign in
Apple Sign In is not offered on every platform:
On iOS and web, post-auth redirects use
/(tabs)/events, the Expo Router path for the tab labeled Gigs:
Configuration
iOS configuration
Apple Sign In requires iOS entitlements. These are configured inapp.config.js:
expo-apple-authentication plugin is included automatically.
Clerk dashboard setup
To enable social authentication:1
Enable OAuth Providers
- Go to Clerk Dashboard
- Navigate to User & Authentication → Social Connections
- Enable Google and/or Apple
2
Configure Google OAuth
- Create OAuth credentials in Google Cloud Console
- Add credentials to Clerk Dashboard
- Configure redirect URLs
3
Configure Apple Sign In
- Enable Sign In with Apple in Apple Developer Console
- Create Services ID for OAuth
- Generate private key
- Add credentials to Clerk Dashboard
Apple Sign In requires an Apple Developer account ($99/year).
Token management
How tokens work
Token lifecycle
- Generation: Clerk creates a JWT when user signs in
- Caching: Token is stored in SecureStore via
tokenCache - Retrieval:
getToken()returns the current valid token - Refresh: Clerk automatically refreshes expired tokens
- Expiration: Tokens expire after 1 hour (configurable in Clerk)
Token format
All authenticated requests include:AuthContext
TheAuthContext provides authentication state throughout the app:
Provider setup
TheAuthProvider must be inside ClerkProvider:
Error handling
Common OAuth errors
User Cancelled OAuth Flow
User Cancelled OAuth Flow
This is expected behavior when users cancel authentication:
Invalid Client Error
Invalid Client Error
The Services ID or configuration doesn’t match between Apple and Clerk:
- Verify Services ID in Clerk matches Apple Developer Console
- Check redirect URLs match exactly
- Ensure the Services ID is enabled for Sign In with Apple
Invalid Grant Error
Invalid Grant Error
Private key or Team ID mismatch:
- Re-enter the private key in Clerk Dashboard
- Verify Team ID is correct (10 characters)
- Verify Key ID is correct (10 characters)
App Doesn't Open After Auth
App Doesn't Open After Auth
OAuth redirect not working:
- Verify
scheme: "soundcheck"inapp.config.js - Rebuild the app with
eas build - Check Clerk Dashboard OAuth redirect configuration
Security
Best practices
- Never commit secrets - Keep Clerk keys in environment variables
- Use SecureStore - Tokens are stored securely in iOS Keychain/Android Keystore
- Short-lived tokens - JWT tokens expire, limiting vulnerability window
- Automatic refresh - Clerk handles token refresh automatically
- Revocable sessions - Sessions can be revoked from Clerk Dashboard
Environment variables
Testing authentication
Debug checklist
-
Check token is being sent:
- Open React Native debugger
- Check Network tab
- Verify
Authorization: Bearer ...header
-
Verify user state:
-
Test with cURL: