From 85f38b5996b1a5b3b342afa6aee4bdf5c17fb557 Mon Sep 17 00:00:00 2001 From: Naif-Deriv Date: Mon, 1 Jul 2024 12:56:24 +0400 Subject: [PATCH] elevate `DerivAtuhService` params to parent class. --- .../example_login_repository.dart | 14 +++++++---- .../login/services/example_login_service.dart | 15 +++++------ packages/deriv_auth/example/lib/main.dart | 9 +++++++ .../features/auth/cubit/deriv_auth_cubit.dart | 5 +--- .../auth/services/base_auth_service.dart | 23 ++++++++++++++++- .../auth/services/deriv_auth_service.dart | 25 +++---------------- 6 files changed, 53 insertions(+), 38 deletions(-) diff --git a/packages/deriv_auth/example/lib/features/login/repositories/example_login_repository.dart b/packages/deriv_auth/example/lib/features/login/repositories/example_login_repository.dart index 2e7f72a29..bd2ad58bc 100644 --- a/packages/deriv_auth/example/lib/features/login/repositories/example_login_repository.dart +++ b/packages/deriv_auth/example/lib/features/login/repositories/example_login_repository.dart @@ -7,15 +7,17 @@ class ExampleLoginRepository implements BaseAuthRepository { Future.value(const AuthorizeResponseEntity()); @override - Future getDefaultAccount() => Future.value(AccountModel( - accountId: "accountId", - )); + Future getDefaultAccount() => Future.value( + AccountModel( + accountId: "accountId", + ), + ); @override Future> getLatestAccounts() => Future.value([ AccountModel( accountId: "accountId", - ) + ), ]); @override @@ -32,5 +34,7 @@ class ExampleLoginRepository implements BaseAuthRepository { @override Future getLandingCompany(String? countryCode) => - Future.value(const LandingCompanyEntity()); + Future.value( + const LandingCompanyEntity(), + ); } diff --git a/packages/deriv_auth/example/lib/features/login/services/example_login_service.dart b/packages/deriv_auth/example/lib/features/login/services/example_login_service.dart index 63c832a4f..8fdc880e9 100644 --- a/packages/deriv_auth/example/lib/features/login/services/example_login_service.dart +++ b/packages/deriv_auth/example/lib/features/login/services/example_login_service.dart @@ -2,22 +2,23 @@ import 'package:deriv_auth/core/models/account_model.dart'; import 'package:deriv_auth/core/models/authorize_model.dart'; import 'package:deriv_auth/core/models/landig_comany_model.dart'; import 'package:deriv_auth/core/services/token/models/login_request.dart'; -import 'package:deriv_auth/features/auth/repository/base_auth_repository.dart'; import 'package:deriv_auth/features/auth/services/base_auth_service.dart'; /// `DerivGO` implementation of [BaseAuthService]. class ExampleLoginService extends BaseAuthService { /// Initializes a [ExampleLoginService] class. ExampleLoginService({ - required this.authRepository, + required super.authRepository, + required super.jwtService, + required super.connectionInfo, + required super.tokenService, }); - /// Interface of all client related functions. - final BaseAuthRepository authRepository; - @override - Future onLoginRequest( - {required GetTokensRequestModel request, String? userAgent}) async => + Future onLoginRequest({ + required GetTokensRequestModel request, + String? userAgent, + }) async => const AuthorizeEntity(); @override diff --git a/packages/deriv_auth/example/lib/main.dart b/packages/deriv_auth/example/lib/main.dart index f16ee0fa0..c329c062c 100644 --- a/packages/deriv_auth/example/lib/main.dart +++ b/packages/deriv_auth/example/lib/main.dart @@ -36,6 +36,15 @@ class MyApp extends StatelessWidget { create: (context) => DerivAuthCubit( authService: ExampleLoginService( authRepository: ExampleLoginRepository(), + jwtService: DerivJwtService( + repository: DerivJwtRepository( + client: HttpClient(), + connectionInfo: DerivAuthConnectionInfo(), + appToken: 'test_app_token', + ), + ), + connectionInfo: DerivAuthConnectionInfo(), + tokenService: DerivTokenService(), ), ), ), diff --git a/packages/deriv_auth/lib/features/auth/cubit/deriv_auth_cubit.dart b/packages/deriv_auth/lib/features/auth/cubit/deriv_auth_cubit.dart index 53eb7fb2a..6b7db78de 100644 --- a/packages/deriv_auth/lib/features/auth/cubit/deriv_auth_cubit.dart +++ b/packages/deriv_auth/lib/features/auth/cubit/deriv_auth_cubit.dart @@ -12,7 +12,6 @@ import 'package:deriv_auth/core/services/token/models/enums.dart'; import 'package:deriv_auth/core/services/token/models/login_request.dart'; import 'package:deriv_auth/features/auth/deriv_auth_io.dart'; import 'package:deriv_auth/features/auth/services/base_auth_service.dart'; -import 'package:deriv_auth/features/auth/services/deriv_auth_service.dart'; import 'package:deriv_auth/features/social_auth/models/social_auth_dto.dart'; part 'deriv_auth_state.dart'; @@ -27,9 +26,7 @@ class DerivAuthCubit extends Cubit required this.authService, }) : super(DerivAuthLoadingState()) { AuthTrackingRepository.init( - authService is DerivAuthService - ? (authService as DerivAuthService).connectionInfo.appId - : (throw Exception('Connection Info is not provided.')), + authService.connectionInfo.appId, derivRudderstack: DerivRudderstack(), ); } diff --git a/packages/deriv_auth/lib/features/auth/services/base_auth_service.dart b/packages/deriv_auth/lib/features/auth/services/base_auth_service.dart index 184acc869..2c07aca21 100644 --- a/packages/deriv_auth/lib/features/auth/services/base_auth_service.dart +++ b/packages/deriv_auth/lib/features/auth/services/base_auth_service.dart @@ -1,12 +1,33 @@ +import 'package:deriv_auth/core/connection_info.dart'; import 'package:deriv_auth/core/models/account_model.dart'; import 'package:deriv_auth/core/models/authorize_model.dart'; import 'package:deriv_auth/core/models/landig_comany_model.dart'; +import 'package:deriv_auth/core/services/jwt/services/base_jwt_service.dart'; import 'package:deriv_auth/core/services/token/models/login_request.dart'; +import 'package:deriv_auth/core/services/token/services/base_token_service.dart'; +import 'package:deriv_auth/features/auth/repository/base_auth_repository.dart'; /// Interface to define all authentication-related functionality. abstract class BaseAuthService { /// Constructor for [BaseAuthService]. - BaseAuthService(); + BaseAuthService({ + required this.connectionInfo, + required this.jwtService, + required this.authRepository, + required this.tokenService, + }); + + /// Client connection info. + final AuthConnectionInfo connectionInfo; + + /// Interface for all jwtRelated functions. + final BaseJwtService jwtService; + + /// Interface of all client related functions. + final BaseAuthRepository authRepository; + + /// Token service. + final BaseTokenService tokenService; /// Function before logging user in. Future onLoginRequest({ diff --git a/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart b/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart index 1a0d6c697..fe64da79c 100644 --- a/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart +++ b/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart @@ -1,6 +1,4 @@ import 'package:collection/collection.dart'; -import 'package:deriv_auth/core/connection_info.dart'; - import 'package:deriv_auth/core/constants/constants.dart'; import 'package:deriv_auth/core/exceptions/deriv_auth_exception.dart'; import 'package:deriv_auth/core/extensions/extensions.dart'; @@ -8,11 +6,8 @@ import 'package:deriv_auth/core/models/account_model.dart'; import 'package:deriv_auth/core/models/auth_error/auth_error.dart'; import 'package:deriv_auth/core/models/authorize_model.dart'; import 'package:deriv_auth/core/models/landig_comany_model.dart'; -import 'package:deriv_auth/core/services/jwt/services/base_jwt_service.dart'; import 'package:deriv_auth/core/services/token/models/login_request.dart'; import 'package:deriv_auth/core/services/token/models/login_response.dart'; -import 'package:deriv_auth/core/services/token/services/base_token_service.dart'; -import 'package:deriv_auth/features/auth/repository/base_auth_repository.dart'; import 'package:deriv_http_client/deriv_http_client.dart'; import 'base_auth_service.dart'; @@ -21,24 +16,12 @@ import 'base_auth_service.dart'; class DerivAuthService extends BaseAuthService { /// Initializes a [DerivAuthService] class. DerivAuthService({ - required this.authRepository, - required this.jwtService, - required this.connectionInfo, - required this.tokenService, + required super.authRepository, + required super.jwtService, + required super.connectionInfo, + required super.tokenService, }); - /// Client connection info. - final AuthConnectionInfo connectionInfo; - - /// Interface for all jwtRelated functions. - final BaseJwtService jwtService; - - /// Interface of all client related functions. - final BaseAuthRepository authRepository; - - /// Token service. - final BaseTokenService tokenService; - @override Future onLoginRequest({ required GetTokensRequestModel request,