mvm.txt 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package com.example.task1.view.mainAct.components
  2. import androidx.lifecycle.ViewModel
  3. import androidx.lifecycle.viewModelScope
  4. import com.example.task1.domain.Constants
  5. import io.github.jan.supabase.gotrue.auth
  6. import io.github.jan.supabase.gotrue.providers.builtin.Email
  7. import io.github.jan.supabase.gotrue.providers.builtin.OTP
  8. import kotlinx.coroutines.launch
  9. class MainViewModel():ViewModel() {
  10. fun onSignInEmailCode(emailUser: String) {
  11. viewModelScope.launch {
  12. try {
  13. Constants.supabase.auth.signInWith(OTP) {
  14. email = emailUser
  15. createUser = false
  16. }
  17. } catch (e: Exception) {
  18. println(e.message.toString())
  19. }
  20. }
  21. }
  22. fun onSignInEmailPassword(emailUser: String, passwordUser: String) {
  23. viewModelScope.launch {
  24. try {
  25. val user = Constants.supabase.auth.signInWith(Email) {
  26. email = emailUser
  27. password = passwordUser
  28. }
  29. println(user.toString())
  30. println(Constants.supabase.auth.currentUserOrNull()!!.id)
  31. println("Success")
  32. } catch (e: Exception) {
  33. println("Error")
  34. println(e.message.toString())
  35. }
  36. }
  37. }
  38. fun onSignUpEmail(emailUser: String, passwordUser: String) {
  39. viewModelScope.launch {
  40. try{
  41. var user = Constants.supabase.auth.signUpWith(Email) {
  42. email = emailUser
  43. password = passwordUser
  44. }
  45. println(user.toString())
  46. println(Constants.supabase.auth.currentUserOrNull()!!.id)
  47. println("Success")
  48. }
  49. catch (e: Exception) {
  50. println("Error")
  51. println(e.message.toString())
  52. }
  53. }
  54. }
  55. }