Skip to content

Commit

Permalink
Merge pull request #43 from frontegg/upgrade-native-sdks
Browse files Browse the repository at this point in the history
Upgrade Frontegg Native SDKs, Add support for loginHint in login action, Login promise now waiting until login process finished
  • Loading branch information
frontegg-david authored Nov 11, 2024
2 parents b3425d0 + c82442a commit a21adc8
Show file tree
Hide file tree
Showing 17 changed files with 355 additions and 208 deletions.
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,13 @@ When you're sending a pull request:
- Review the documentation to make sure it looks good.
- Follow the pull request template when opening a pull request.
- For pull requests that change the API or implementation, discuss with maintainers first by opening an issue.



### Common iOS build issues:
- If you encounter an error like 'Sandbox: rsync.samba(73955) deny(1) file-write-create' when running the iOS app, you can fix it by update to cocoapods 1.16.0 or higher **OR** freeze xcodeproj to 1.25 the following command:
- https://github.com/CocoaPods/CocoaPods/releases/tag/1.16.0
```sh
sudo gem uninstall xcodeproj -x --ignore-dependencies
sudo gem install xcodeproj -v 1.25.1
```
4 changes: 2 additions & 2 deletions FronteggRN.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ Pod::Spec.new do |s|
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
if respond_to?(:install_modules_dependencies, true)
install_modules_dependencies(s)
s.dependency "FronteggSwift", "1.2.21"
s.dependency "FronteggSwift", "1.2.26"
else
s.dependency "React-Core"
s.dependency "FronteggSwift", "1.2.21"
s.dependency "FronteggSwift", "1.2.26"

# Don't install the dependencies when we run `pod install` in the old architecture.
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
Expand Down
4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ dependencies {
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "androidx.browser:browser:1.5.0"
implementation "androidx.browser:browser:1.8.0"
implementation 'io.reactivex.rxjava3:rxkotlin:3.0.1'
implementation 'com.frontegg.sdk:android:1.2.25'
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'com.frontegg.sdk:android:1.2.30'
}

if (isNewArchitectureEnabled()) {
Expand Down
63 changes: 31 additions & 32 deletions android/src/main/java/com/frontegg/reactnative/FronteggRNModule.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
package com.frontegg.reactnative

import android.app.Activity
import android.content.Intent
import android.os.Handler
import android.os.Looper
import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.BaseActivityEventListener
import com.facebook.react.bridge.Promise
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactContextBaseJavaModule
import com.facebook.react.bridge.ReactMethod
import com.facebook.react.bridge.WritableMap
import com.facebook.react.common.LifecycleState
import com.facebook.react.modules.core.DeviceEventManagerModule
import com.frontegg.android.AuthenticationActivity
import com.frontegg.android.FronteggApp
import com.frontegg.android.FronteggAuth
import io.reactivex.rxjava3.core.Observable
Expand All @@ -28,29 +24,7 @@ class FronteggRNModule(val reactContext: ReactApplicationContext) :
return NAME
}

private val activityEventListener = object : BaseActivityEventListener() {
override fun onActivityResult(
activity: Activity?,
requestCode: Int,
resultCode: Int,
intent: Intent?
) {
if (requestCode == AuthenticationActivity.OAUTH_LOGIN_REQUEST) {
when (resultCode) {
Activity.RESULT_CANCELED -> {
loginPromise?.reject("Canceled")
}

Activity.RESULT_OK -> {
loginPromise?.resolve("OK")
}
}
}
}
}

init {
reactContext.addActivityEventListener(activityEventListener)
fronteggConstants = reactContext.fronteggConstants


Expand Down Expand Up @@ -86,6 +60,7 @@ class FronteggRNModule(val reactContext: ReactApplicationContext) :
this.disposable = Observable.mergeArray(
FronteggAuth.instance.accessToken.observable,
FronteggAuth.instance.refreshToken.observable,
FronteggAuth.instance.refreshingToken.observable,
FronteggAuth.instance.user.observable,
FronteggAuth.instance.isAuthenticated.observable,
FronteggAuth.instance.isLoading.observable,
Expand All @@ -112,6 +87,7 @@ class FronteggRNModule(val reactContext: ReactApplicationContext) :
handler.removeCallbacks(eventRunnable)
val accessToken = FronteggAuth.instance.accessToken.value
val refreshToken = FronteggAuth.instance.refreshToken.value
val refreshingToken = FronteggAuth.instance.refreshingToken.value
val user = FronteggAuth.instance.user.value
val isAuthenticated = FronteggAuth.instance.isAuthenticated.value
val isLoading = FronteggAuth.instance.isLoading.value
Expand All @@ -122,6 +98,7 @@ class FronteggRNModule(val reactContext: ReactApplicationContext) :

putString("accessToken", accessToken)
putString("refreshToken", refreshToken)
putBoolean("refreshingToken", refreshingToken)
putMap("user", user?.toReadableMap())
putBoolean("isAuthenticated", isAuthenticated)
putBoolean("isLoading", isLoading)
Expand All @@ -148,14 +125,12 @@ class FronteggRNModule(val reactContext: ReactApplicationContext) :

}


private var loginPromise: Promise? = null

@ReactMethod
fun login(promise: Promise) {
fun login(loginHint: String?, promise: Promise) {
val activity = currentActivity
loginPromise = promise
FronteggAuth.instance.login(activity!!)
FronteggAuth.instance.login(activity!!, loginHint) {
promise.resolve("")
}
}

@ReactMethod
Expand All @@ -178,6 +153,30 @@ class FronteggRNModule(val reactContext: ReactApplicationContext) :
promise.resolve("")
}

@ReactMethod
fun loginWithPasskeys(promise: Promise) {
val activity = currentActivity
FronteggAuth.instance.loginWithPasskeys(activity!!) {
if (it != null) {
promise.reject(it)
} else {
promise.resolve("")
}
}
}

@ReactMethod
fun registerPasskeys(promise: Promise) {
val activity = currentActivity
FronteggAuth.instance.registerPasskeys(activity!!) {
if (it != null) {
promise.reject(it)
} else {
promise.resolve("")
}
}
}

override fun getConstants(): MutableMap<String, Any?> = fronteggConstants.toMap()

companion object {
Expand Down
2 changes: 1 addition & 1 deletion example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def enableProguardInReleaseBuilds = false
*/
def jscFlavor = 'org.webkit:android-jsc:+'

def fronteggDomain = "auth.davidantoon.me"
def fronteggDomain = "autheu.davidantoon.me"
def fronteggClientId = "b6adfe4c-d695-4c04-b95f-3ec9fd0c6cca"

android {
Expand Down
12 changes: 6 additions & 6 deletions example/ios/Frontegg.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>baseUrl</key>
<string>https://auth.davidantoon.me</string>
<key>clientId</key>
<string>b6adfe4c-d695-4c04-b95f-3ec9fd0c6cca</string>
<key>logLevel</key>
<string>trace</string>
<key>baseUrl</key>
<string>https://autheu.davidantoon.me</string>
<key>clientId</key>
<string>b6adfe4c-d695-4c04-b95f-3ec9fd0c6cca</string>
<key>logLevel</key>
<string>trace</string>
</dict>
</plist>
12 changes: 6 additions & 6 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ PODS:
- React-jsi (= 0.72.1)
- ReactCommon/turbomodule/core (= 0.72.1)
- fmt (6.2.1)
- FronteggRN (1.2.6):
- FronteggSwift (= 1.2.21)
- FronteggRN (1.2.8):
- FronteggSwift (= 1.2.26)
- RCT-Folly (= 2021.07.22.00)
- React-Core
- FronteggSwift (1.2.21)
- FronteggSwift (1.2.26)
- glog (0.3.5)
- hermes-engine (0.72.1):
- hermes-engine/Pre-built (= 0.72.1)
Expand Down Expand Up @@ -584,8 +584,8 @@ SPEC CHECKSUMS:
FBLazyVector: 55cd4593d570bd9e5e227488d637ce6a9581ce51
FBReactNativeSpec: 799b0e1a1561699cd0e424e24fe5624da38402f0
fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9
FronteggRN: 1cdcefed548ca7953a1bbb0b7f12c9584cdcaf2d
FronteggSwift: b7eba3a2d7ab0fa89c793c32c1be31c64b27db42
FronteggRN: 7adf3791e2a25fa246ea41a5e692f308ccf81539
FronteggSwift: a92b852ed3721627dcbef0dfc985380c0fa4eb60
glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b
hermes-engine: 9df83855a0fd15ef8eb61694652bae636b0c466e
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
Expand Down Expand Up @@ -628,4 +628,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 010992354d93ba29cfe4cff5fab47f9b2920a2da

COCOAPODS: 1.15.2
COCOAPODS: 1.16.2
Loading

0 comments on commit a21adc8

Please sign in to comment.