|
@@ -1,6 +1,7 @@
|
|
|
package com.example.tasks.screens
|
|
|
|
|
|
import android.health.connect.datatypes.units.Length
|
|
|
+import android.util.Log
|
|
|
import android.widget.Toast
|
|
|
import androidx.compose.foundation.background
|
|
|
import androidx.compose.foundation.border
|
|
@@ -61,19 +62,34 @@ import androidx.compose.ui.text.style.TextAlign
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
import androidx.navigation.NavController
|
|
|
+import com.example.tasks.components.Constants
|
|
|
+import com.example.tasks.model.User
|
|
|
import com.example.tasks.model.UserState
|
|
|
import com.example.tasks.navigation.Screen
|
|
|
import com.example.tasks.viewModels.AuthViewModel
|
|
|
+import io.github.jan.supabase.postgrest.from
|
|
|
+import io.github.jan.supabase.postgrest.query.Columns
|
|
|
+import kotlinx.coroutines.Dispatchers
|
|
|
import kotlinx.coroutines.delay
|
|
|
+import kotlinx.coroutines.withContext
|
|
|
|
|
|
@Composable
|
|
|
fun EnterOTP(navController: NavController,email:String,viewModel: AuthViewModel) {
|
|
|
+ var users by remember { mutableStateOf<List<User>>(listOf()) }
|
|
|
val userState by viewModel.userState
|
|
|
var currentUserState by remember { mutableStateOf("") }
|
|
|
val focusManager = LocalFocusManager.current
|
|
|
var flag = remember { mutableStateOf(false) }
|
|
|
val context = LocalContext.current
|
|
|
val keyboardController = LocalSoftwareKeyboardController.current
|
|
|
+ LaunchedEffect(Unit) {
|
|
|
+ withContext(Dispatchers.IO) {
|
|
|
+ users = Constants.supabase.from("Users")
|
|
|
+ .select(columns = Columns.list("UID")){
|
|
|
+ filter { User::UID eq viewModel.userID
|
|
|
+ }}.decodeList<User>()
|
|
|
+ }
|
|
|
+ }
|
|
|
val textList = listOf(
|
|
|
remember {
|
|
|
mutableStateOf(
|
|
@@ -225,7 +241,7 @@ fun EnterOTP(navController: NavController,email:String,viewModel: AuthViewModel)
|
|
|
onClick = {
|
|
|
val token = token(textList)
|
|
|
viewModel.verifyOTP(email, token)
|
|
|
- flag.value = true },
|
|
|
+ flag.value = true },
|
|
|
Modifier
|
|
|
.fillMaxWidth()
|
|
|
.height(50.dp),
|
|
@@ -249,7 +265,13 @@ fun EnterOTP(navController: NavController,email:String,viewModel: AuthViewModel)
|
|
|
is UserState.Success -> {
|
|
|
val message = (userState as UserState.Success).message
|
|
|
currentUserState = message
|
|
|
- navController.navigate(Screen.CreateProfile.route)
|
|
|
+ if(users.isNotEmpty()){
|
|
|
+ navController.navigate(Screen.Profile.route)
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ navController.navigate(Screen.CreateProfile.route)
|
|
|
+ }
|
|
|
+
|
|
|
flag.value = false
|
|
|
}
|
|
|
|