Supabase Google Sign-In – Android (Kotlin)
An Android application demonstrating Google Sign-In authentication using Supabase Auth with Kotlin.
This project uses:
- Supabase Auth
- Google Identity Services (Credential Manager)
- Material Components
- Kotlin Coroutines
🚀 Features
- Google Sign-In using Supabase
- Secure ID Token authentication
- Session persistence
- Auto-login on app restart
- Logout functionality
- Display logged-in user name
- Material Design UI
🛠 Tech Stack
- Kotlin
- Android SDK
- Supabase Kotlin SDK
- Google Identity Services
- Material Components
🔐 Authentication Flow
- User selects Google account.
- App retrieves Google ID Token.
- ID Token is sent to Supabase.
- Supabase verifies token and creates session.
- Session is persisted locally.
- User is automatically logged in on next launch.
⚙️ Setup Instructions
1️⃣ Clone the repository
git clone https://github.com/TutorialsAndroid/SupaBaseGoogleSignIn.git
2️⃣ Create Supabase Project
Authentication → Providers → Google
- Add your Google Web Client ID & Secret
You must create:
✅ Web OAuth Client
Used inside the app for setServerClientId.
✅ Android OAuth Client
Required for SHA-1 verification.
Steps:
Enable:
- Google Identity Services API
4️⃣ Add Keys to local.properties
Add this to local.properties:
SUPABASE_URL=your_supabase_url
SUPABASE_ANON_KEY=your_anon_public_key
GOOGLE_WEB_CLIENT_ID=your_web_client_id
5️⃣ BuildConfig Setup
Keys are loaded into BuildConfig via Gradle.
Make sure your build.gradle includes:
buildConfigField("String", "SUPABASE_URL", "\"${localProperties["SUPABASE_URL"]}\"")
buildConfigField("String", "SUPABASE_ANON_KEY", "\"${localProperties["SUPABASE_ANON_KEY"]}\"")
buildConfigField("String", "GOOGLE_WEB_CLIENT_ID", "\"${localProperties["GOOGLE_WEB_CLIENT_ID"]}\"")
🧠 Auto Login Handling
Supabase restores session asynchronously.
To prevent race conditions, a short coroutine delay is used before checking:
delay(200)
if (supabase.auth.currentSessionOrNull() != null) {
navigateToHome()
}
🔓 Logout
lifecycleScope.launch {
supabase.auth.signOut()
}
📂 Project Structure
App.kt → Supabase initialization
SignInActivity.kt → Google login
HomeActivity.kt → Display user info + logout
🛡 Security Notes
- Uses Supabase
anon public key (safe for client apps)
- Never expose
service_role key
- Enable Row Level Security (RLS) in Supabase
- Google SHA-1 verification required
📌 Important Notes
- Emulator must have Google Play image
- A Google account must be added on device
- SHA-1 must match Android OAuth client
🎯 Future Improvements
- Splash screen auth state observer
- MVVM architecture
- Profile editing
- Upload avatar
- Store additional user data in database
评论