Skip to content

Commit 02771e0

Browse files
committed
Codderrabit comment resolutions
1 parent 6450ede commit 02771e0

9 files changed

Lines changed: 45 additions & 17 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ sessions.pem
8787
# Verdaccio
8888
.verdaccio
8989

90+
# yalc
91+
.yalc/
92+
yalc.lock
93+
9094
# Release preflight
9195
.release-artifacts/
9296

packages/expo/android/src/main/java/expo/modules/clerk/ClerkAuthActivity.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

packages/expo/android/src/main/java/expo/modules/clerk/ClerkAuthExpoView.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ import kotlinx.coroutines.launch
3232

3333
private const val TAG = "ClerkAuthExpoView"
3434

35+
private fun debugLog(tag: String, message: String) {
36+
if (BuildConfig.DEBUG) {
37+
Log.d(tag, message)
38+
}
39+
}
40+
3541
class ClerkAuthNativeView(context: Context) : FrameLayout(context) {
3642
var mode: String = "signInOrUp"
3743
var isDismissable: Boolean = true
@@ -73,7 +79,7 @@ class ClerkAuthNativeView(context: Context) : FrameLayout(context) {
7379
private var initialSessionId: String? = Clerk.session?.id
7480

7581
fun setupView() {
76-
Log.d(TAG, "setupView - mode: $mode, isDismissable: $isDismissable, activity: $activity")
82+
debugLog(TAG, "setupView - mode: $mode, isDismissable: $isDismissable, activity: $activity")
7783

7884
composeView.setContent {
7985
val session by Clerk.sessionFlow.collectAsStateWithLifecycle()
@@ -82,7 +88,7 @@ class ClerkAuthNativeView(context: Context) : FrameLayout(context) {
8288
LaunchedEffect(session) {
8389
val currentSession = session
8490
if (currentSession != null && initialSessionId == null) {
85-
Log.d(TAG, "Auth completed - session: ${currentSession.id}")
91+
debugLog(TAG, "Auth completed - session present: true")
8692
sendEvent("signInCompleted", mapOf(
8793
"sessionId" to currentSession.id,
8894
"type" to "signIn"

packages/expo/android/src/main/java/expo/modules/clerk/ClerkExpoModule.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class ClerkExpoModule(reactContext: ReactApplicationContext) :
181181
val session = Clerk.session
182182
val user = Clerk.user
183183

184-
debugLog(TAG, "getSession - session: ${session?.id}, user: ${user?.id}")
184+
debugLog(TAG, "getSession - hasSession: ${session != null}, hasUser: ${user != null}")
185185

186186
val result = WritableNativeMap()
187187

@@ -267,7 +267,7 @@ class ClerkExpoModule(reactContext: ReactApplicationContext) :
267267
val session = Clerk.session
268268
val user = Clerk.user
269269

270-
debugLog(TAG, "handleAuthResult - session: ${session?.id}, user: ${user?.id}")
270+
debugLog(TAG, "handleAuthResult - hasSession: ${session != null}, hasUser: ${user != null}")
271271

272272
val result = WritableNativeMap()
273273

packages/expo/android/src/main/java/expo/modules/clerk/ClerkUserProfileActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class ClerkUserProfileActivity : ComponentActivity() {
4747
val publishableKey = intent.getStringExtra(ClerkExpoModule.EXTRA_PUBLISHABLE_KEY)
4848

4949
debugLog(TAG, "onCreate - isInitialized: ${Clerk.isInitialized.value}")
50-
debugLog(TAG, "onCreate - session: ${Clerk.session?.id}, user: ${Clerk.user?.id}")
50+
debugLog(TAG, "onCreate - hasSession: ${Clerk.session != null}, hasUser: ${Clerk.user != null}")
5151

5252
// Initialize Clerk if not already initialized
5353
if (publishableKey != null && !Clerk.isInitialized.value) {
@@ -65,7 +65,7 @@ class ClerkUserProfileActivity : ComponentActivity() {
6565

6666
// Log when user/session state changes
6767
LaunchedEffect(user, session) {
68-
debugLog(TAG, "State changed - session: ${session?.id}, user: ${user?.id}")
68+
debugLog(TAG, "State changed - hasSession: ${session != null}, hasUser: ${user != null}")
6969
}
7070

7171
// Detect sign-out: if we had a session and now it's null, user signed out

packages/expo/ios/ClerkExpo.podspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Pod::Spec.new do |s|
2424
s.license = package['license']
2525
s.author = package['author']
2626
s.homepage = package['homepage']
27+
# NOTE: Must match CLERK_MIN_IOS_VERSION in app.plugin.js
2728
s.platforms = { :ios => '17.0' } # Clerk iOS SDK requires iOS 17
2829
s.swift_version = '5.10'
2930
s.source = { git: 'https://github.com/clerk/javascript' }

packages/expo/ios/ClerkViewFactory.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import ClerkExpo // Import the pod to access ClerkViewFactoryProtocol
1414
public class ClerkViewFactory: ClerkViewFactoryProtocol {
1515
public static let shared = ClerkViewFactory()
1616

17+
private static let clerkLoadMaxAttempts = 30
18+
private static let clerkLoadIntervalNs: UInt64 = 100_000_000
19+
1720
private init() {}
1821

1922
// Register this factory with the ClerkExpo module
@@ -36,11 +39,11 @@ public class ClerkViewFactory: ClerkViewFactoryProtocol {
3639

3740
// Wait for Clerk to finish loading (cached data + API refresh).
3841
// The static configure() fires off async refreshes; poll until loaded.
39-
for _ in 0..<30 { // Wait up to 3 seconds
42+
for _ in 0..<Self.clerkLoadMaxAttempts {
4043
if Clerk.shared.isLoaded && Clerk.shared.session != nil {
4144
return
4245
}
43-
try? await Task.sleep(nanoseconds: 100_000_000) // 100ms
46+
try? await Task.sleep(nanoseconds: Self.clerkLoadIntervalNs)
4447
}
4548
}
4649

packages/expo/ios/templates/ClerkViewFactory.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import ClerkExpo // Import the pod to access ClerkViewFactoryProtocol
1414
public class ClerkViewFactory: ClerkViewFactoryProtocol {
1515
public static let shared = ClerkViewFactory()
1616

17+
private static let clerkLoadMaxAttempts = 30
18+
private static let clerkLoadIntervalNs: UInt64 = 100_000_000
19+
1720
private init() {}
1821

1922
// Register this factory with the ClerkExpo module
@@ -36,11 +39,11 @@ public class ClerkViewFactory: ClerkViewFactoryProtocol {
3639

3740
// Wait for Clerk to finish loading (cached data + API refresh).
3841
// The static configure() fires off async refreshes; poll until loaded.
39-
for _ in 0..<30 { // Wait up to 3 seconds
42+
for _ in 0..<Self.clerkLoadMaxAttempts {
4043
if Clerk.shared.isLoaded && Clerk.shared.session != nil {
4144
return
4245
}
43-
try? await Task.sleep(nanoseconds: 100_000_000) // 100ms
46+
try? await Task.sleep(nanoseconds: Self.clerkLoadIntervalNs)
4447
}
4548
}
4649

packages/expo/src/native/UserButton.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useClerk, useUser } from '@clerk/react';
2-
import { useEffect, useState } from 'react';
2+
import { useEffect, useRef, useState } from 'react';
33
import type { StyleProp, ViewStyle } from 'react-native';
44
import { Image, Platform, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
55

@@ -134,6 +134,7 @@ export interface UserButtonProps {
134134
*/
135135
export function UserButton({ onPress, onSignOut, style }: UserButtonProps) {
136136
const [nativeUser, setNativeUser] = useState<NativeUser | null>(null);
137+
const presentingRef = useRef(false);
137138
const clerk = useClerk();
138139
// Use the reactive user hook from clerk-react to observe sign-out state changes
139140
const { user: clerkUser } = useUser();
@@ -176,12 +177,17 @@ export function UserButton({ onPress, onSignOut, style }: UserButtonProps) {
176177
: null);
177178

178179
const handlePress = async () => {
180+
if (presentingRef.current) {
181+
return;
182+
}
183+
179184
onPress?.();
180185

181186
if (!isNativeSupported || !ClerkExpo?.presentUserProfile) {
182187
return;
183188
}
184189

190+
presentingRef.current = true;
185191
try {
186192
await ClerkExpo.presentUserProfile({
187193
dismissable: true,
@@ -224,6 +230,8 @@ export function UserButton({ onPress, onSignOut, style }: UserButtonProps) {
224230
}
225231
} catch {
226232
// Modal was dismissed by the user — not an error
233+
} finally {
234+
presentingRef.current = false;
227235
}
228236
};
229237

0 commit comments

Comments
 (0)