|
@@ -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())
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|