This is a robust starter template for React Native (Expo) apps featuring Supabase Authentication with Google Sign-In, persistent session management, and a clean file structure.
- Authentication: Google Sign-In via Supabase Auth (PKCE flow).
- Session Management: Auto-refreshing sessions using
expo-secure-storeadapter. - Navigation: File-based routing with
expo-router. - UI: Clean, responsive UI using standard
StyleSheet. - TypeScript: Fully typed codebase.
Before you begin, ensure you have:
- Node.js installed.
- An Expo account.
- A Supabase project.
- A Google Cloud project.
-
Clone the repository (or use this template):
git clone https://github.com/mannbhatt/expo-supabase-google-auth-template.git cd expo-supabase-google-auth-template -
Install dependencies:
npm install # or yarn install
- Go to your Supabase Dashboard.
- Navigate to Settings > API.
- Copy your Project URL and anon public key.
- Rename
.env.exampleto.envand paste your keys:EXPO_PUBLIC_SUPABASE_URL=your_supabase_url EXPO_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key
Open app.json and customize your app's identity:
- Name & Slug: Change
"name"and"slug"to your project name. - Bundle Identifier (iOS): Update
ios.bundleIdentifier(e.g.,com.yourname.project). - Package Name (Android): Update
android.package(e.g.,com.yourname.project). - Scheme: Update
"scheme". This is crucial for deep linking (e.g., changeauthsetuptoyour-app-scheme).
Important: If you change the
schemeinapp.json, you must also update the scheme inlib/auth.ts:// lib/auth.ts const redirectUrl = Linking.createURL("auth/callback", { scheme: "your-app-scheme" });
-
Google Cloud Console:
- Create a new project.
- Configure the OAuth Consent Screen.
- Create OAuth 2.0 Client IDs:
- Web Client ID: Required for Supabase.
- iOS Client ID: Use your Bundle Identifier.
- Android Client ID: Use your Package Name and SHA-1 certificate fingerprint.
-
Supabase Auth Settings:
- Go to Authentication > Providers > Google.
- Enable Google.
- Paste your Web Client ID (from Google Cloud) into the "Client ID" field.
- (Optional) Paste your Client Secret if verified.
- Redirect URL: Add your app's deep link scheme to the Redirect URLs list in Supabase (Authentication > URL Configuration):
- Format:
your-app-scheme://auth/callback(e.g.,authsetup://auth/callback) - Also add:
com.yourname.project://auth/callback(for Android intents)
- Format:
Start the development server:
npx expo startRun on Android:
npx expo run:androidRun on iOS:
npx expo run:iosapp/: Expo Router pages.(auth)/: Public auth screens (Login).(tabs)/: Protected app screens (Home, Profile)._layout.tsx: Root layout with auth protection logic.
components/: Reusable UI components.context/: React Contexts (AuthProvider).lib/:auth.ts: Google Sign-In logic.supabaseClient.ts: Supabase client configuration.ui.ts: Responsive UI helpers.
If you are migrating this code to another project, ensure you install:
npx expo install @supabase/supabase-js @react-native-async-storage/async-storage @expo-google-fonts/manrope expo-auth-session expo-crypto expo-linking expo-router expo-secure-store expo-web-browser expo-splash-screen react-native-get-random-values react-native-url-polyfill- "Redirect URL mismatch": Ensure the URL scheme in
app.json,lib/auth.ts, and Supabase Dashboard (URL Configuration) matches exactly. - "Google Sign In Error": formatting of the SHA-1 fingerprint for Android or Bundle ID for iOS in Google Cloud Console must be correct.
- "Logs appearing in terminal": Check
lib/supabaseClient.tsand setdebug: falseif you want to silence Supabase logs.