Ver Fonte

Need make normal auth

CoolVery há 1 mês atrás
pai
commit
39f0b8658c

+ 0 - 1
.idea/misc.xml

@@ -1,4 +1,3 @@
-<?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
   <component name="ExternalStorageConfigurationManager" enabled="true" />
   <component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">

+ 6 - 6
app/build.gradle.kts

@@ -71,12 +71,12 @@ dependencies {
     debugImplementation(libs.androidx.ui.tooling)
     debugImplementation(libs.androidx.ui.test.manifest)
 
-    implementation(platform("io.github.jan-tennert.supabase:bom:2.6.1"))
-    implementation("io.github.jan-tennert.supabase:postgrest-kt")
-    implementation("io.github.jan-tennert.supabase:gotrue-kt")
-    implementation("io.github.jan-tennert.supabase:realtime-kt")
-    implementation("io.github.jan-tennert.supabase:storage-kt")
-    implementation("io.ktor:ktor-client-android:2.3.12")
+    implementation(platform(libs.bom))
+    implementation(libs.supabase.postgrest.kt)
+    implementation(libs.supabase.gotrue.kt)
+    implementation(libs.supabase.realtime.kt)
+    implementation(libs.storage.kt)
+    implementation(libs.ktor.client.android)
 
 
 

+ 25 - 1
app/src/main/java/com/example/collectionofshortstories/MainActivity.kt

@@ -1,6 +1,8 @@
 package com.example.collectionofshortstories
 
 import android.os.Bundle
+import android.provider.ContactsContract.Contacts
+import android.util.Log
 import androidx.activity.ComponentActivity
 import androidx.activity.compose.setContent
 import androidx.activity.enableEdgeToEdge
@@ -13,8 +15,17 @@ import androidx.compose.material3.Text
 import androidx.compose.runtime.Composable
 import androidx.compose.ui.Modifier
 import androidx.compose.ui.tooling.preview.Preview
+import androidx.compose.ui.unit.Constraints
+import androidx.lifecycle.Lifecycle
+import androidx.lifecycle.LifecycleEventObserver
+import androidx.lifecycle.LifecycleOwner
+import androidx.lifecycle.ProcessLifecycleOwner
+import androidx.lifecycle.lifecycleScope
+import com.example.collectionofshortstories.domain.untils.Constants
 import com.example.collectionofshortstories.navigation.Navigathion
 import com.example.collectionofshortstories.ui.theme.CollectionOfShortStoriesTheme
+import io.github.jan.supabase.gotrue.auth
+import kotlinx.coroutines.launch
 
 class MainActivity : ComponentActivity() {
     override fun onCreate(savedInstanceState: Bundle?) {
@@ -22,7 +33,7 @@ class MainActivity : ComponentActivity() {
         enableEdgeToEdge()
         setContent {
             CollectionOfShortStoriesTheme {
-                Surface (
+                Surface(
                     modifier = Modifier.fillMaxSize(),
                     color = MaterialTheme.colorScheme.background
                 ) {
@@ -30,6 +41,19 @@ class MainActivity : ComponentActivity() {
                 }
             }
         }
+
+        ProcessLifecycleOwner.get().lifecycle.addObserver(object : LifecycleEventObserver {
+            override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) {
+                if (event == Lifecycle.Event.ON_DESTROY) {
+                    // Запуск сопрограммы для вызова signOut()
+                    lifecycleScope.launch {
+                        Log.d("exit","yes")
+                        Constants.supabase.auth.signOut()
+
+                    }
+                }
+            }
+        })
     }
 }
 

+ 4 - 3
app/src/main/java/com/example/collectionofshortstories/view/authorization/AuthorizationAndLoginViewModel.kt

@@ -1,5 +1,6 @@
 package com.example.collectionofshortstories.view.authorization
 
+import android.util.Log
 import androidx.lifecycle.ViewModel
 import androidx.lifecycle.viewModelScope
 import androidx.navigation.NavHostController
@@ -11,18 +12,18 @@ import io.github.jan.supabase.gotrue.providers.builtin.Email
 import kotlinx.coroutines.launch
 
 class AuthorizationViewModel(): ViewModel() {
+
+
     fun onSignInEmailPassword(emailUser: String, passwordUser: String) {
         viewModelScope.launch {
             try {
-                println("Start")
                 val user = Constants.supabase.auth.signInWith(Email) {
                     email = emailUser
                     password = passwordUser
 
                 }
-                if (Constants.supabase.auth.currentUserOrNull() != null) {
+                Log.d("user", Constants.supabase.auth.currentUserOrNull()!!.id.toString())
 
-                }
             } catch (e: Exception) {
                 println("Error")
                 println(e.message.toString())

+ 6 - 4
app/src/main/java/com/example/collectionofshortstories/view/catalog/CatalogViewModel.kt

@@ -49,9 +49,11 @@ class CatalogViewModel(): ViewModel() {
                     filter {
                         eq("id", Constants.supabase.auth.currentUserOrNull()!!.id)
                     }
-                }
-                val userRoleId = userDate.decodeSingle<User>().id_role
-                Log.d("DSDSDSDSD", userRoleId.toString())
+                }.decodeSingleOrNull<User>()
+                println(userDate.toString())
+                println(userDate!!.id_role.toString())
+                val userRoleId = userDate.id_role
+                println(userRoleId.toString())
                 val roleDate = Constants.supabase.from("roles")
                     .select {
                         filter {
@@ -66,7 +68,7 @@ class CatalogViewModel(): ViewModel() {
                     _role_name.value = roleDate.title
                 }
             } catch (e: Exception){
-                Log.d("DSDSDSDSD","пипец")
+                Log.d("DSDSDSDSD",e.message.toString())
             }
 
 

+ 7 - 1
gradle/libs.versions.toml

@@ -1,11 +1,12 @@
 [versions]
-agp = "8.6.0"
+agp = "8.5.1"
 bom = "2.6.1"
 kotlin = "1.9.0"
 coreKtx = "1.10.1"
 junit = "4.13.2"
 junitVersion = "1.1.5"
 espressoCore = "3.5.1"
+ktorClientAndroid = "2.3.12"
 ktorClientEngine_z = "2.3.12"
 lifecycleRuntimeKtx = "2.6.1"
 activityCompose = "1.8.0"
@@ -34,9 +35,14 @@ androidx-material3 = { group = "androidx.compose.material3", name = "material3"
 androidx-navigation-runtime-ktx = { group = "androidx.navigation", name = "navigation-runtime-ktx", version.ref = "navigationRuntimeKtx" }
 androidx-work-runtime-ktx = { group = "androidx.work", name = "work-runtime-ktx", version.ref = "workRuntimeKtx" }
 androidx-navigation-compose = { group = "androidx.navigation", name = "navigation-compose", version.ref = "navigationCompose" }
+ktor-client-android = { module = "io.ktor:ktor-client-android", version.ref = "ktorClientAndroid" }
 ktor-client-engine_z = { module = "io.ktor:ktor-client-[engine]", version.ref = "ktorClientEngine_z" }
 realtime-kt = { module = "io.github.jan-tennert.supabase:realtime-kt" }
 postgrest-kt = { module = "io.github.jan-tennert.supabase:postgrest-kt" }
+storage-kt = { module = "io.github.jan-tennert.supabase:storage-kt" }
+supabase-gotrue-kt = { module = "io.github.jan-tennert.supabase:gotrue-kt" }
+supabase-postgrest-kt = { module = "io.github.jan-tennert.supabase:postgrest-kt" }
+supabase-realtime-kt = { module = "io.github.jan-tennert.supabase:realtime-kt" }
 
 [plugins]
 android-application = { id = "com.android.application", version.ref = "agp" }