瀏覽代碼

changesInAuth

x1tosi 1 月之前
父節點
當前提交
8edc8434fe

+ 1 - 0
.idea/.name

@@ -0,0 +1 @@
+fitmarcetplaceKuzminIv

+ 0 - 17
app/src/main/java/com/example/fitmarcetplacekuzminiv/MainViewModel.kt

@@ -5,27 +5,10 @@ import androidx.lifecycle.viewModelScope
 import com.example.fitmarcetplacekuzminiv.domain.Constants
 import io.github.jan.supabase.gotrue.auth
 import io.github.jan.supabase.gotrue.providers.builtin.Email
-import io.github.jan.supabase.gotrue.providers.builtin.OTP
 import kotlinx.coroutines.launch
 
 class MainViewModel():ViewModel() {
 
-    fun onSignInEmailCode(emailUser: String) {
-        viewModelScope.launch {
-            try {
-                Constants.supabase.auth.signInWith(OTP) {
-                    email = emailUser
-                    createUser = false
-                }
-
-            } catch (e: Exception) {
-                println(e.message.toString())
-
-            }
-
-        }
-    }
-
     fun onSignInEmailPassword(emailUser: String, passwordUser: String) {
         viewModelScope.launch {
             try {

+ 10 - 23
app/src/main/java/com/example/fitmarcetplacekuzminiv/Screens/authScreen.kt

@@ -13,6 +13,7 @@ import androidx.compose.ui.tooling.preview.Preview
 import androidx.compose.ui.unit.dp
 import androidx.compose.ui.text.input.PasswordVisualTransformation
 import androidx.compose.ui.text.input.TextFieldValue
+import androidx.compose.ui.unit.sp
 import androidx.lifecycle.viewmodel.compose.viewModel
 import com.example.fitmarcetplacekuzminiv.MainViewModel
 
@@ -31,8 +32,9 @@ class AuthScreenActivity : ComponentActivity() {
 
 @Composable
 fun AuthScreen(mainViewModel: MainViewModel = viewModel()) {
-    var email by remember { mutableStateOf(TextFieldValue("")) }
-    var password by remember { mutableStateOf(TextFieldValue("")) }
+    val viewModel = MainViewModel()
+    val email = remember { mutableStateOf("") }
+    val password = remember { mutableStateOf("") }
     var errorMessage by remember { mutableStateOf("") }
     var successMessage by remember { mutableStateOf("") }
 
@@ -48,41 +50,26 @@ fun AuthScreen(mainViewModel: MainViewModel = viewModel()) {
                 .padding(16.dp)
         ) {
             OutlinedTextField(
-                value = email,
-                onValueChange = { email = it },
+                value = email.value,
+                onValueChange = { newText -> email.value = newText },
                 label = { Text("Email") },
                 modifier = Modifier.fillMaxWidth()
             )
             Spacer(modifier = Modifier.height(16.dp))
             OutlinedTextField(
-                value = password,
-                onValueChange = { password = it },
+                value = password.value,
+                onValueChange = { newText -> password.value = newText },
                 label = { Text("Password") },
                 visualTransformation = PasswordVisualTransformation(),
                 modifier = Modifier.fillMaxWidth()
             )
             Spacer(modifier = Modifier.height(24.dp))
             Button(onClick = {
-                // Вызов авторизации через email и пароль
-                if (email.text.isNotEmpty() && password.text.isNotEmpty()) {
-                    mainViewModel.onSignInEmailPassword(email.text, password.text)
-                } else {
-                    errorMessage = "Заполните все поля"
-                }
-            }) {
+                viewModel.onSignInEmailPassword(email.value,password.value)
+            }){
                 Text("Login")
             }
 
-            // Отображение ошибок или успешного входа
-            if (errorMessage.isNotEmpty()) {
-                Spacer(modifier = Modifier.height(16.dp))
-                Text(text = errorMessage, color = MaterialTheme.colorScheme.error)
-            }
-
-            if (successMessage.isNotEmpty()) {
-                Spacer(modifier = Modifier.height(16.dp))
-                Text(text = successMessage, color = MaterialTheme.colorScheme.primary)
-            }
         }
     }
 }

+ 2 - 4
app/src/main/java/com/example/fitmarcetplacekuzminiv/domain/Constants.kt

@@ -1,10 +1,9 @@
 package com.example.fitmarcetplacekuzminiv.domain
 
-import android.net.http.HttpResponseCache.install
-//import com.google.android.gms.auth.api.Auth
+
+import com.google.android.gms.auth.api.signin.internal.Storage
 import io.github.jan.supabase.createSupabaseClient
 import io.github.jan.supabase.gotrue.Auth
-import io.github.jan.supabase.gotrue.SessionSource
 import io.github.jan.supabase.postgrest.Postgrest
 
 object Constants {
@@ -14,7 +13,6 @@ object Constants {
     ) {
         install(Auth)
         install(Postgrest)
-        //install(SessionSource.Storage)
     }
 
 }