@@ -55,6 +55,9 @@ class ClerkAuthActivity : ComponentActivity() {
5555
5656 companion object {
5757 private const val TAG = " ClerkAuthActivity"
58+ private const val CLIENT_SYNC_MAX_ATTEMPTS = 30
59+ private const val CLIENT_SYNC_INTERVAL_MS = 100L
60+ private const val POLL_INTERVAL_MS = 500L
5861
5962 private fun debugLog (tag : String , message : String ) {
6063 if (BuildConfig .DEBUG ) {
@@ -73,7 +76,7 @@ class ClerkAuthActivity : ComponentActivity() {
7376
7477 // Track if we had a session when we started (to detect new sign-in)
7578 val initialSession = Clerk .session
76- debugLog(TAG , " onCreate - initialSession : ${initialSession?.id } , mode: $mode " )
79+ debugLog(TAG , " onCreate - hasInitialSession : ${initialSession != null } , mode: $mode " )
7780
7881 setContent {
7982 // Observe initialization state
@@ -98,14 +101,14 @@ class ClerkAuthActivity : ComponentActivity() {
98101 // Give the client a moment to sync after initialization
99102 // The SDK needs time to fetch the environment configuration
100103 var attempts = 0
101- while (attempts < 30 ) { // Wait up to 3 seconds
104+ while (attempts < CLIENT_SYNC_MAX_ATTEMPTS ) {
102105 val client = Clerk .client
103106 if (client != null ) {
104- debugLog(TAG , " Client is ready: ${client.id} " )
107+ debugLog(TAG , " Client is ready" )
105108 isClientReady = true
106109 break
107110 }
108- delay(100 )
111+ delay(CLIENT_SYNC_INTERVAL_MS )
109112 attempts++
110113 }
111114 if (! isClientReady) {
@@ -127,13 +130,13 @@ class ClerkAuthActivity : ComponentActivity() {
127130 LaunchedEffect (isClientReady) {
128131 if (isClientReady) {
129132 while (true ) {
130- delay(500 ) // Check every 500ms
133+ delay(POLL_INTERVAL_MS )
131134 val client = Clerk .client
132135 val signUp = client?.signUp
133136
134137 if (signUp != null && signUp.id != lastSignUpId) {
135138 lastSignUpId = signUp.id
136- debugLog(TAG , " New signUp detected: ${signUp.id} , status: ${signUp.status} " )
139+ debugLog(TAG , " New signUp detected, status: ${signUp.status} " )
137140 }
138141
139142 // Manually trigger prepareVerification if needed
0 commit comments