Skip to content

Commit

Permalink
elevate DerivAtuhService params to parent class.
Browse files Browse the repository at this point in the history
  • Loading branch information
naif-deriv committed Jul 1, 2024
1 parent 701f453 commit 85f38b5
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ class ExampleLoginRepository implements BaseAuthRepository {
Future.value(const AuthorizeResponseEntity());

@override
Future<AccountModel?> getDefaultAccount() => Future.value(AccountModel(
accountId: "accountId",
));
Future<AccountModel?> getDefaultAccount() => Future.value(
AccountModel(
accountId: "accountId",
),
);

@override
Future<List<AccountModel>> getLatestAccounts() => Future.value([
AccountModel(
accountId: "accountId",
)
),
]);

@override
Expand All @@ -32,5 +34,7 @@ class ExampleLoginRepository implements BaseAuthRepository {

@override
Future<LandingCompanyEntity> getLandingCompany(String? countryCode) =>
Future.value(const LandingCompanyEntity());
Future.value(
const LandingCompanyEntity(),
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<AuthorizeEntity> onLoginRequest(
{required GetTokensRequestModel request, String? userAgent}) async =>
Future<AuthorizeEntity> onLoginRequest({
required GetTokensRequestModel request,
String? userAgent,
}) async =>
const AuthorizeEntity();

@override
Expand Down
9 changes: 9 additions & 0 deletions packages/deriv_auth/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -27,9 +26,7 @@ class DerivAuthCubit extends Cubit<DerivAuthState>
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(),
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<AuthorizeEntity> onLoginRequest({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
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';
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';
Expand All @@ -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<AuthorizeEntity> onLoginRequest({
required GetTokensRequestModel request,
Expand Down

0 comments on commit 85f38b5

Please sign in to comment.