Skip to content
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

FR-17412 - Upgrade frontegg native SDKs #17

Merged
merged 3 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ android {
testImplementation 'org.mockito:mockito-core:5.0.0'

// Frontegg dependencies
implementation 'com.frontegg.sdk:android:1.2.18'
implementation 'com.frontegg.sdk:android:1.2.23'
// Utils
implementation 'androidx.core:core-ktx:1.10.0'
implementation 'io.reactivex.rxjava3:rxkotlin:3.0.1'
Expand Down
10 changes: 5 additions & 5 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
PODS:
- Flutter (1.0.0)
- frontegg_flutter (1.0.0):
- frontegg_flutter (1.0.1):
- Flutter
- FronteggSwift (~> 1.2.16)
- FronteggSwift (1.2.16)
- FronteggSwift (~> 1.2.18)
- FronteggSwift (1.2.18)
- integration_test (0.0.1):
- Flutter

Expand All @@ -26,8 +26,8 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
frontegg_flutter: eaa577629a5ff05a1db35cb334d9e7f83a81163a
FronteggSwift: 38b780c7d1bf4a708317f86dd5ce2e4e11ce71d2
frontegg_flutter: 82bcc84bd42968665498d298931161a9b85d6882
FronteggSwift: 321b0399468d237948bb9c5e53aacedb82c0f980
integration_test: 252f60fa39af5e17c3aa9899d35d908a0721b573

PODFILE CHECKSUM: 1959d098c91d8a792531a723c4a9d7e9f6a01e38
Expand Down
21 changes: 15 additions & 6 deletions example/lib/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,21 @@ class LoginPage extends StatelessWidget {
if (state.isLoading) {
return const CircularProgressIndicator();
} else if (!state.initializing && !state.isAuthenticated) {
return ElevatedButton(
child: const Text("Login"),
onPressed: () {
frontegg.login();
},
);
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
child: const Text("Login"),
onPressed: () {
frontegg.login();
}),
ElevatedButton(
child: const Text("Login with Google"),
onPressed: () {
frontegg.directLoginAction("social-login", "google");
},
)
]);
}
}
return const SizedBox();
Expand Down
4 changes: 2 additions & 2 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,10 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: f652077d0bdf60abe4c1f6377448e8655008eef28f128bc023f7b5e8dfeb48fc
sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"
url: "https://pub.dev"
source: hosted
version: "14.2.4"
version: "14.2.5"
webdriver:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion ios/frontegg_flutter.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ A new Flutter plugin project.
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.dependency 'Flutter'
s.dependency 'FronteggSwift', '~> 1.2.16'
s.dependency 'FronteggSwift', '~> 1.2.18'
s.platform = :ios, '14.0'

# Flutter.framework does not contain a i386 slice.
Expand Down
56 changes: 48 additions & 8 deletions lib/src/frontegg_method_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,95 @@ import "package:flutter/services.dart";

import "frontegg_platform_interface.dart";

/// FronteggMethodChannel is the platform-specific implementation of the
/// FronteggPlatform interface using MethodChannels to communicate with
/// the native platform.
class FronteggMethodChannel extends FronteggPlatform {
// Method channel and event channel names
static const String methodChannelName = "frontegg_flutter";
static const String stateEventChannelName = "frontegg_flutter/state_stream";

// Method names for platform-specific method calls
static const String loginMethodName = "login";
static const String logoutMethodName = "logout";
static const String switchTenantMethodName = "switchTenant";
static const String directLoginActionMethodName = "directLoginAction";
static const String refreshTokenMethodName = "refreshToken";
static const String getConstantsMethodName = "getConstants";

/// MethodChannel used for invoking platform-specific methods.
@visibleForTesting
final methodChannel = const MethodChannel(methodChannelName);

/// EventChannel used for listening to state changes from the native platform.
@visibleForTesting
final stateChangedEventChanel = const EventChannel(stateEventChannelName);

/// A stream that provides broadcast events from the native platform
/// related to state changes.
late final Stream<dynamic> _stateChangedEventChanelStream =
stateChangedEventChanel.receiveBroadcastStream();
stateChangedEventChanel.receiveBroadcastStream();

/// Stream to listen to state changes from the native platform.
@override
Stream get stateChanged => _stateChangedEventChanelStream;

/// Initiates the login process by invoking the native platform's login method.
///
/// Returns a [Future] that completes when the login process is finished.
@override
Future<void> login() => methodChannel.invokeMethod(loginMethodName);

/// Switches the current tenant by invoking the native platform's switchTenant method.
///
/// [tenantId]: The ID of the tenant to switch to.
///
/// Returns a [Future] that completes when the tenant switch process is finished.
@override
Future<void> switchTenant(String tenantId) => methodChannel.invokeMethod(
switchTenantMethodName,
{
"tenantId": tenantId,
},
);
switchTenantMethodName,
{
"tenantId": tenantId,
},
);

/// Performs a direct login action by invoking the native platform's directLoginAction method.
///
/// [type]: The type of login action to perform.
/// [data]: The data associated with the login action.
/// [ephemeralSession]: Optional boolean indicating whether the session should be ephemeral (not sharing session with default browser). Defaults to true.
///
/// Returns a [Future] that completes when the login action is finished.
@override
Future<void> directLoginAction(String type, String data) => methodChannel.invokeMethod(
Future<void> directLoginAction(String type, String data,
{bool ephemeralSession = true}) =>
methodChannel.invokeMethod(
directLoginActionMethodName,
{
"type": type,
"data": data,
"ephemeralSession": ephemeralSession,
frontegg-david marked this conversation as resolved.
Show resolved Hide resolved
},
);

/// Refreshes the current session token by invoking the native platform's refreshToken method.
///
/// Returns a [Future] that completes with a boolean value indicating
/// whether the token refresh was successful.
@override
Future<bool?> refreshToken() => methodChannel.invokeMethod<bool>(refreshTokenMethodName);
Future<bool?> refreshToken() =>
methodChannel.invokeMethod<bool>(refreshTokenMethodName);

/// Logs the user out by invoking the native platform's logout method.
///
/// Returns a [Future] that completes when the logout process is finished.
@override
Future<void> logout() => methodChannel.invokeMethod(logoutMethodName);

/// Retrieves a map of constants from the native platform.
///
/// Returns a [Future] that completes with a map containing key-value pairs
/// of constants from the native platform.
@override
Future<Map<Object?, Object?>?> getConstants() =>
methodChannel.invokeMethod<Map<Object?, Object?>>(getConstantsMethodName);
Expand Down
Loading