You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
val resendTimerSeconds = rememberSaveable { mutableIntStateOf(0) }
161
+
val pendingVerificationPhoneNumber = remember { mutableStateOf<String?>(null) }
162
+
val verificationStartTime = remember { mutableStateOf<Long?>(null) }
161
163
162
164
val authState by authUI.authStateFlow().collectAsState(AuthState.Idle)
163
165
val isLoading = authState isAuthState.Loading
@@ -190,6 +192,10 @@ fun PhoneAuthScreen(
190
192
191
193
isAuthState.SMSAutoVerified-> {
192
194
// Auto-verification succeeded, sign in with the credential
195
+
// and clear pending verification tracking
196
+
pendingVerificationPhoneNumber.value =null
197
+
verificationStartTime.value =null
198
+
193
199
coroutineScope.launch {
194
200
try {
195
201
authUI.signInWithPhoneAuthCredential(
@@ -247,6 +253,33 @@ fun PhoneAuthScreen(
247
253
onSendCodeClick = {
248
254
coroutineScope.launch {
249
255
try {
256
+
val currentTime =System.currentTimeMillis()
257
+
val timeoutMs = provider.timeout *1000
258
+
val timeSinceLastVerification = verificationStartTime.value?.let {
259
+
currentTime - it
260
+
} ?:Long.MAX_VALUE
261
+
262
+
// Check if the same phone number is being verified again within the cooldown period
263
+
val storedNumber = pendingVerificationPhoneNumber.value
264
+
val isSameNumber = storedNumber !=null&& fullPhoneNumber == storedNumber
265
+
266
+
// Check cooldown: same number and still within timeout period
267
+
if (isSameNumber && timeSinceLastVerification < timeoutMs) {
268
+
// Calculate remaining cooldown time in seconds
269
+
val remainingCooldownSeconds = ((timeoutMs - timeSinceLastVerification) /1000).coerceAtLeast(1)
270
+
val cooldownException =AuthException.PhoneVerificationCooldownException(
271
+
message ="Please wait ${remainingCooldownSeconds} second${if (remainingCooldownSeconds !=1L) "s"else""} before verifying the same phone number again. The cooldown period is ${provider.timeout} seconds.",
0 commit comments