-
Notifications
You must be signed in to change notification settings - Fork 452
feat(expo): add two-way JS/native session sync for expo native components #8032
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
9168040
4461fa2
96ca76d
3b1d3ee
edd9d86
78b41dd
bdd15bd
39d3e70
118eb56
4f8bd2d
751e803
c87fe1d
137f430
79215bd
dea03dc
bc0d928
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -170,37 +170,6 @@ class ClerkExpoModule: RCTEventEmitter { | |
| } | ||
| } | ||
|
|
||
| // MARK: - getClientToken | ||
|
|
||
| @objc func getClientToken(_ resolve: @escaping RCTPromiseResolveBlock, | ||
| reject: @escaping RCTPromiseRejectBlock) { | ||
| // Use a custom keychain service if configured in Info.plist (for extension apps | ||
| // sharing a keychain group). Falls back to the main bundle identifier. | ||
| let keychainService: String = { | ||
| if let custom = Bundle.main.object(forInfoDictionaryKey: "ClerkKeychainService") as? String, !custom.isEmpty { | ||
| return custom | ||
| } | ||
| return Bundle.main.bundleIdentifier ?? "" | ||
| }() | ||
|
|
||
| let query: [String: Any] = [ | ||
| kSecClass as String: kSecClassGenericPassword, | ||
| kSecAttrService as String: keychainService, | ||
| kSecAttrAccount as String: "clerkDeviceToken", | ||
| kSecReturnData as String: true, | ||
| kSecMatchLimit as String: kSecMatchLimitOne | ||
| ] | ||
|
|
||
| var result: AnyObject? | ||
| let status = SecItemCopyMatching(query as CFDictionary, &result) | ||
|
|
||
| if status == errSecSuccess, let data = result as? Data { | ||
| resolve(String(data: data, encoding: .utf8)) | ||
| } else { | ||
| resolve(nil) | ||
| } | ||
| } | ||
|
|
||
| // MARK: - signOut | ||
|
|
||
| @objc func signOut(_ resolve: @escaping RCTPromiseResolveBlock, | ||
|
Comment on lines
199
to
201
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 👍 / 👎.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 A fix has been provided for this now as well. |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious about the use of reflection here. Generally considered an anti pattern in Java world
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clerk.initialize() is a no-op if the SDK is already initialized, and the Clerk Android SDK doesn't expose any public API to force a re-initialization or swap the device token post-init. We need to trigger a fresh client/environment fetch after writing a new bearer token to SharedPreferences, and there's no way to do that (as far as I can tell) from the android SDK.
The reflection approach finds ConfigurationManager by type (to be resilient to field name changes across SDK versions), then finds the _isInitialized MutableStateFlow and flips it to false so reinitialize() will proceed.
Let me know if you can think of a cleaner way to do it, and I'll put it in!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can add those hooks for you in the Android SDK to avoid it if you'd like?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've pushed a commit that drops the entire reflection hack and uses
updateDeviceToken()instead. It saves the token viaStorageHelperand triggersrefreshClientAndEnvironment()internally.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Things are working well. I am going to approve the PR here: clerk/clerk-android#564 (review)
If you can publish to maven, that would be amazing!