The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
docs: update sample
Hieu Vu85a861dd5f30
diff --git a/examples/product-sample-supabase-kt/app/src/main/AndroidManifest.xml b/examples/product-sample-supabase-kt/app/src/main/AndroidManifest.xmlindex 3ce2a8a88c6..60d13ac1a04 100644--- a/examples/product-sample-supabase-kt/app/src/main/AndroidManifest.xml+++ b/examples/product-sample-supabase-kt/app/src/main/AndroidManifest.xml@@ -1,17 +1,31 @@<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools">- <uses-permission android:name="android.permission.INTERNET"/>+ <uses-permission android:name="android.permission.INTERNET" /><applicationandroid:name=".ManageProductApplication"android:allowBackup="true"android:dataExtractionRules="@xml/data_extraction_rules"+ android:enableOnBackInvokedCallback="true"android:fullBackupContent="@xml/backup_rules"android:icon="@mipmap/ic_launcher"android:label="@string/app_name"android:supportsRtl="true"android:theme="@style/Theme.ManageProducts"tools:targetApi="31">+ <activity+ android:name=".DeepLinkHandlerActivity"+ android:exported="true"+ android:theme="@style/Theme.ManageProducts" >+ <intent-filter android:autoVerify="true">+ <action android:name="android.intent.action.VIEW" />+ <category android:name="android.intent.category.DEFAULT" />+ <category android:name="android.intent.category.BROWSABLE" />+ <data+ android:host="supabase.com"+ android:scheme="app" />+ </intent-filter>+ </activity><activityandroid:name=".MainActivity"android:exported="true"@@ -19,10 +33,8 @@android:theme="@style/Theme.ManageProducts"><intent-filter><action android:name="android.intent.action.MAIN" />-<category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity></application>-</manifest>\ No newline at end of filediff --git a/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/DeepLinkHandlerActivity.kt b/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/DeepLinkHandlerActivity.ktnew file mode 100644index 00000000000..0ecd879deba--- /dev/null+++ b/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/DeepLinkHandlerActivity.kt@@ -0,0 +1,72 @@+package com.example.manageproducts++import android.content.Intent+import android.os.Bundle+import android.util.Log+import androidx.activity.ComponentActivity+import androidx.activity.compose.setContent+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.padding+import androidx.compose.material3.MaterialTheme+import androidx.compose.material3.Surface+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.ui.Modifier+import androidx.compose.ui.unit.dp+import androidx.navigation.compose.rememberNavController+import com.example.manageproducts.presentation.feature.signin.SignInSuccessScreen+import com.example.manageproducts.ui.theme.ManageProductsTheme+import dagger.hilt.android.AndroidEntryPoint+import io.github.jan.supabase.SupabaseClient+import io.github.jan.supabase.gotrue.handleDeeplinks+import javax.inject.Inject++@AndroidEntryPoint+class DeepLinkHandlerActivity : ComponentActivity() {++ @Inject+ lateinit var supabaseClient: SupabaseClient++ private lateinit var callback: (String, String) -> Unit+ override fun onCreate(savedInstanceState: Bundle?) {+ super.onCreate(savedInstanceState)+ supabaseClient.handleDeeplinks(intent = intent,+ onSessionSuccess = { userSession ->+ Log.d("LOGIN", "Log in successfully with user info: ${userSession.user}")+ userSession.user?.apply {+ callback(email ?: "", createdAt.toString())+ }+ })+ setContent {+ val navController = rememberNavController()+ val emailState = remember { mutableStateOf("") }+ val createdAtState = remember { mutableStateOf("") }+ callback = { email, created ->+ emailState.value = email+ createdAtState.value = created+ }+ ManageProductsTheme {+ Surface(+ modifier = Modifier.fillMaxSize(),+ color = MaterialTheme.colorScheme.background+ ) {+ SignInSuccessScreen(+ modifier = Modifier.padding(20.dp),+ navController = navController,+ email = emailState.value,+ createdAt = createdAtState.value,+ onClick = { navigateToMainApp() }+ )+ }+ }+ }+ }++ private fun navigateToMainApp() {+ val intent = Intent(this, MainActivity::class.java).apply {+ flags = Intent.FLAG_ACTIVITY_CLEAR_TOP+ }+ startActivity(intent)+ }+}+diff --git a/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/data/repository/AuthenticationRepository.kt b/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/data/repository/AuthenticationRepository.ktindex edac2c23a24..3727734607e 100644--- a/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/data/repository/AuthenticationRepository.kt+++ b/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/data/repository/AuthenticationRepository.kt@@ -3,4 +3,5 @@ package com.example.manageproducts.data.repositoryinterface AuthenticationRepository {suspend fun signIn(email: String, password: String): Booleansuspend fun signUp(email: String, password: String): Boolean+ suspend fun signInWithGoogle(): Boolean}\ No newline at end of filediff --git a/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/data/repository/impl/AuthenticationRepositoryImpl.kt b/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/data/repository/impl/AuthenticationRepositoryImpl.ktindex 68535d45eda..4decea8877e 100644--- a/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/data/repository/impl/AuthenticationRepositoryImpl.kt+++ b/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/data/repository/impl/AuthenticationRepositoryImpl.kt@@ -31,4 +31,13 @@ class AuthenticationRepositoryImpl @Inject constructor(false}}++ override suspend fun signInWithGoogle(): Boolean {+ return try {+ goTrue.loginWith(Google)+ true+ } catch (e: Exception) {+ false+ }+ }}\ No newline at end of filediff --git a/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/di/UseCaseModule.kt b/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/di/UseCaseModule.ktindex 52c6bae49f4..20f6f92ad6c 100644--- a/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/di/UseCaseModule.kt+++ b/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/di/UseCaseModule.kt@@ -31,4 +31,7 @@ abstract class UseCaseModule {@Bindsabstract fun bindSignUpUseCase(impl: SignUpUseCaseImpl): SignUpUseCase++ @Binds+ abstract fun bindSignInWithGoogleUseCase(impl: SignInWithGoogleUseCaseImpl): SignInWithGoogleUseCase}\ No newline at end of filediff --git a/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/domain/usecase/SignInWithGoogleUseCase.kt b/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/domain/usecase/SignInWithGoogleUseCase.ktnew file mode 100644index 00000000000..09c0aa651a6--- /dev/null+++ b/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/domain/usecase/SignInWithGoogleUseCase.kt@@ -0,0 +1,7 @@+package com.example.manageproducts.domain.usecase++interface SignInWithGoogleUseCase: UseCase<SignInWithGoogleUseCase.Input, SignInWithGoogleUseCase.Output> {+ class Input++ class Output+}\ No newline at end of filediff --git a/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/domain/usecase/impl/SignInWithGoogleUseCaseImpl.kt b/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/domain/usecase/impl/SignInWithGoogleUseCaseImpl.ktnew file mode 100644index 00000000000..57998fbb6fd--- /dev/null+++ b/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/domain/usecase/impl/SignInWithGoogleUseCaseImpl.kt@@ -0,0 +1,18 @@+package com.example.manageproducts.domain.usecase.impl++import com.example.manageproducts.data.repository.AuthenticationRepository+import com.example.manageproducts.domain.usecase.SignInWithGoogleUseCase+import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.withContext+import javax.inject.Inject++class SignInWithGoogleUseCaseImpl @Inject constructor(+ private val authenticationRepository: AuthenticationRepository,+): SignInWithGoogleUseCase {+ override suspend fun execute(input: SignInWithGoogleUseCase.Input): SignInWithGoogleUseCase.Output {+ return withContext(Dispatchers.IO) {+ authenticationRepository.signInWithGoogle()+ SignInWithGoogleUseCase.Output()+ }+ }+}\ No newline at end of filediff --git a/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/presentation/feature/signin/SignInScreen.kt b/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/presentation/feature/signin/SignInScreen.ktindex 8de22f49135..08599c509a3 100644--- a/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/presentation/feature/signin/SignInScreen.kt+++ b/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/presentation/feature/signin/SignInScreen.kt@@ -102,6 +102,14 @@ fun SignInScreen(.padding(top = 12.dp),onClick = {localSoftwareKeyboardController?.hide()+ viewModel.onGoogleSignIn()+ }) {+ Text("Sign in with Google")+ }+ Button(modifier = modifier+ .fillMaxWidth()+ .padding(top = 12.dp),+ onClick = {viewModel.onSignIn()coroutineScope.launch {snackBarHostState.showSnackbar(diff --git a/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/presentation/feature/signin/SignInSuccessScreen.kt b/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/presentation/feature/signin/SignInSuccessScreen.ktnew file mode 100644index 00000000000..36f71e6f9da--- /dev/null+++ b/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/presentation/feature/signin/SignInSuccessScreen.kt@@ -0,0 +1,34 @@+package com.example.manageproducts.presentation.feature.signin++import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.runtime.Composable+import androidx.compose.ui.Modifier+import androidx.compose.ui.unit.dp+import androidx.navigation.NavController+import androidx.compose.material3.Text+import androidx.compose.material3.Button++@Composable+fun SignInSuccessScreen(+ navController: NavController,+ modifier: Modifier = Modifier,+ email: String,+ createdAt: String,+ onClick: () -> Unit = {},+) {+ Column(modifier = modifier.fillMaxWidth()) {+ Text(text = "Sign in successfully!")+ Text(text = "Email $email")+ Text(text = "Created at $createdAt")+ Button(+ modifier = modifier+ .fillMaxWidth()+ .padding(top = 12.dp),+ onClick = onClick+ ) {+ Text("Continue")+ }+ }+}diff --git a/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/presentation/feature/signin/SignInViewModel.kt b/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/presentation/feature/signin/SignInViewModel.ktindex 1d5141af532..66f2bc9647e 100644--- a/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/presentation/feature/signin/SignInViewModel.kt+++ b/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/presentation/feature/signin/SignInViewModel.kt@@ -11,7 +11,8 @@ import javax.inject.Inject@HiltViewModelclass SignInViewModel @Inject constructor(- private val signInUseCase: SignInUseCase+ private val signInUseCase: SignInUseCase,+ private val signInWithGoogleUseCase: SignInWithGoogleUseCase,) : ViewModel() {private val _email = MutableStateFlow<String>("")@@ -49,4 +50,10 @@ class SignInViewModel @Inject constructor(}}}++ fun onGoogleSignIn() {+ viewModelScope.launch {+ signInWithGoogleUseCase.execute(SignInWithGoogleUseCase.Input())+ }+ }}\ No newline at end of file