瀏覽代碼

add MainViewModel

Иван 2 周之前
父節點
當前提交
81539aa3f0
共有 1 個文件被更改,包括 46 次插入0 次删除
  1. 46 0
      Project/app/src/main/java/com/example/mygymapp/view/mainActivity/MainViewModel.kt

+ 46 - 0
Project/app/src/main/java/com/example/mygymapp/view/mainActivity/MainViewModel.kt

@@ -0,0 +1,46 @@
+package com.example.mygymapp.view.mainActivity
+
+import androidx.lifecycle.ViewModel
+import androidx.lifecycle.viewModelScope
+import com.example.mygymapp.domain.Constants
+import io.github.jan.supabase.auth.auth
+import io.github.jan.supabase.auth.providers.builtin.Email
+import kotlinx.coroutines.launch
+
+class MainViewModel:ViewModel() {
+
+    fun onSignInEmailPassword(emailUser: String, passwordUser: String) {
+        viewModelScope.launch {
+            try {
+                val user = Constants.supabase.auth.signInWith(Email) {
+                    email = emailUser
+                    password = passwordUser
+                }
+                println(user.toString())
+                println(Constants.supabase.auth.currentUserOrNull()!!.id)
+                println("Success")
+            } catch (e: Exception) {
+                println("Error")
+                println(e.message.toString())
+            }
+        }
+    }
+    fun onSignUpEmail(emailUser: String, passwordUser: String) {
+        viewModelScope.launch {
+            try{
+                var  user =  Constants.supabase.auth.signUpWith(Email) {
+                    email = emailUser
+                    password = passwordUser
+                }
+                println(user.toString())
+                println(Constants.supabase.auth.currentUserOrNull()!!.id)
+                println("Success")
+            }
+            catch (e: Exception) {
+                println("Error")
+                println(e.message.toString())
+            }
+
+        }
+    }
+}