Skip to content

TutorialsAndroid/SupaBaseGoogleSignIn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

  1. User selects Google account.
  2. App retrieves Google ID Token.
  3. ID Token is sent to Supabase.
  4. Supabase verifies token and creates session.
  5. Session is persisted locally.
  6. 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

3️⃣ Configure Google Cloud

You must create:

✅ Web OAuth Client

Used inside the app for setServerClientId.

✅ Android OAuth Client

Required for SHA-1 verification.

Steps:

  • Go to Google Cloud Console

  • APIs & Services → Credentials

  • Create OAuth Client ID

  • Add:

    • Package name
    • SHA-1 (from signingReport)

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

About

An Android application demonstrating Google Sign-In authentication using Supabase Auth with Kotlin.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors