diff --git a/packages/deriv_auth/lib/features/login/presentation/layouts/deriv_login_layout.dart b/packages/deriv_auth/lib/features/login/presentation/layouts/deriv_login_layout.dart index cebec3622..f6b8253ea 100644 --- a/packages/deriv_auth/lib/features/login/presentation/layouts/deriv_login_layout.dart +++ b/packages/deriv_auth/lib/features/login/presentation/layouts/deriv_login_layout.dart @@ -40,7 +40,7 @@ class DerivLoginLayout extends StatefulWidget { final Function(DerivAuthErrorState)? onLoginError; /// Callback to be called when user is logged in. - final Function(DerivAuthLoggedInState) onLoggedIn; + final Function(BuildContext, DerivAuthLoggedInState) onLoggedIn; /// Callback to be called when social auth button is tapped. /// Give access to [SocialAuthDto] for 2FA. @@ -309,7 +309,7 @@ class _DerivLoginLayoutState extends State { } if (state is DerivAuthLoggedInState) { - widget.onLoggedIn.call(state); + widget.onLoggedIn.call(context, state); } } diff --git a/packages/deriv_auth/lib/features/single_entry/core/auth_data.dart b/packages/deriv_auth/lib/features/single_entry/core/auth_data.dart index a611c3682..1478de792 100644 --- a/packages/deriv_auth/lib/features/single_entry/core/auth_data.dart +++ b/packages/deriv_auth/lib/features/single_entry/core/auth_data.dart @@ -1,5 +1,11 @@ // ignore_for_file: unnecessary_getters_setters +import 'package:deriv_auth/core/services/jwt/repository/deriv_jwt_repository.dart'; +import 'package:deriv_auth/core/services/jwt/services/deriv_jwt_service.dart'; +import 'package:deriv_auth/core/services/token/services/deriv_token_service.dart'; +import 'package:deriv_auth/features/auth/auth.dart'; +import 'package:deriv_auth/features/social_auth/cubit/social_auth_cubit.dart'; + import 'models/auth_entry_model.dart'; /// Authentication Data Singleton diff --git a/packages/deriv_auth/lib/features/single_entry/core/auth_provider.dart b/packages/deriv_auth/lib/features/single_entry/core/auth_provider.dart new file mode 100644 index 000000000..f6fb0adcb --- /dev/null +++ b/packages/deriv_auth/lib/features/single_entry/core/auth_provider.dart @@ -0,0 +1,51 @@ +import 'package:deriv_auth/features/auth/cubit/deriv_auth_cubit.dart'; +import 'package:deriv_auth/features/reset_password/cubit/reset_password_cubit.dart'; +import 'package:deriv_auth/features/signup/cubit/signup_cubit.dart'; +import 'package:deriv_auth/features/social_auth/cubit/social_auth_cubit.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; + +/// A wrapper class for clients apps to provide auth related cubits to the context. +class AuthProvider extends StatelessWidget { + /// Constructor [AuthProvider] + const AuthProvider({ + required this.widget, + required this.derivAuthCubit, + required this.socialAuthCubit, + required this.derivResetPassCubit, + required this.derivSignupCubit, + }); + + /// Child widget + final Widget widget; + + /// Instance of Auth Cubit + final DerivAuthCubit derivAuthCubit; + + /// Instance of Social Auth Cubit + final SocialAuthCubit socialAuthCubit; + + /// Instance of Reset Pass Cubit + final DerivResetPassCubit derivResetPassCubit; + + /// Instance of Signup Cubit + final DerivSignupCubit derivSignupCubit; + + Widget build(BuildContext context) => MultiBlocProvider( + providers: [ + BlocProvider.value( + value: derivAuthCubit, + ), + BlocProvider.value( + value: socialAuthCubit, + ), + BlocProvider.value( + value: derivResetPassCubit, + ), + BlocProvider.value( + value: derivSignupCubit, + ), + ], + child: widget, + ); +} diff --git a/packages/deriv_auth/lib/features/single_entry/core/models/login_page_model.dart b/packages/deriv_auth/lib/features/single_entry/core/models/login_page_model.dart index bfb98d9ef..3bac56864 100644 --- a/packages/deriv_auth/lib/features/single_entry/core/models/login_page_model.dart +++ b/packages/deriv_auth/lib/features/single_entry/core/models/login_page_model.dart @@ -1,4 +1,5 @@ import 'package:deriv_auth/deriv_auth.dart'; +import 'package:flutter/material.dart'; /// LoginPageModel class class LoginPageModel { @@ -25,7 +26,7 @@ class LoginPageModel { final Function(DerivAuthErrorState)? onLoginError; /// Callback to be called when user is logged in. - final Function(DerivAuthLoggedInState) onLoggedIn; + final Function(BuildContext, DerivAuthLoggedInState) onLoggedIn; /// Callback to be called when social auth button is tapped. /// Give access to [SocialAuthDto] for 2FA. diff --git a/packages/deriv_auth/lib/features/single_entry/features/login/pages/login_page.dart b/packages/deriv_auth/lib/features/single_entry/features/login/pages/login_page.dart index 7df28097f..0fee5c411 100644 --- a/packages/deriv_auth/lib/features/single_entry/features/login/pages/login_page.dart +++ b/packages/deriv_auth/lib/features/single_entry/features/login/pages/login_page.dart @@ -1,7 +1,6 @@ import 'package:deriv_auth/features/auth/cubit/deriv_auth_cubit.dart'; import 'package:deriv_auth/features/login/presentation/layouts/deriv_login_layout.dart'; import 'package:deriv_auth/features/single_entry/core/auth_data.dart'; -import 'package:deriv_auth/features/single_entry/features/home/pages/home_page.dart'; import 'package:deriv_auth/features/single_entry/features/reset_pass/pages/reset_pass_page.dart'; import 'package:deriv_auth/features/single_entry/features/signup/pages/signup_page.dart'; import 'package:flutter/material.dart'; @@ -27,12 +26,7 @@ class _LoginPageState extends State { Widget build(BuildContext context) => DerivLoginLayout( welcomeLabel: AuthData().data.loginPageModel.welcomeLabel, greetingLabel: AuthData().data.loginPageModel.greetingLabel, - onLoggedIn: (_) => Navigator.pushReplacement( - context, - MaterialPageRoute( - builder: (BuildContext context) => const HomePage(), - ), - ), + onLoggedIn: AuthData().data.loginPageModel.onLoggedIn, authErrorStateHandler: AuthData().data.loginPageModel.authErrorStateHandler, onLoginError: AuthData().data.loginPageModel.onLoginError, diff --git a/packages/deriv_auth/test/features/login/presentation/layouts/deriv_login_layout_test.dart b/packages/deriv_auth/test/features/login/presentation/layouts/deriv_login_layout_test.dart index e2427526e..f5a1bbe4b 100644 --- a/packages/deriv_auth/test/features/login/presentation/layouts/deriv_login_layout_test.dart +++ b/packages/deriv_auth/test/features/login/presentation/layouts/deriv_login_layout_test.dart @@ -67,7 +67,7 @@ void main() { greetingLabel: greetingLabel, onResetPassTapped: () {}, onSignupTapped: () {}, - onLoggedIn: (_) {}, + onLoggedIn: (BuildContext context, _) {}, onSocialAuthButtonPressed: (SocialAuthDto p0) {}, onLoginError: (_) {}, ), @@ -104,7 +104,7 @@ void main() { greetingLabel: greetingLabel, onResetPassTapped: () {}, onSignupTapped: () {}, - onLoggedIn: (_) {}, + onLoggedIn: (BuildContext context, _) {}, onSocialAuthButtonPressed: (_) {}, onLoginError: (_) {}, ), @@ -143,7 +143,7 @@ void main() { greetingLabel: greetingLabel, onResetPassTapped: () {}, onSignupTapped: () {}, - onLoggedIn: (_) {}, + onLoggedIn: (BuildContext context, _) {}, onSocialAuthButtonPressed: (_) {}, onLoginError: (_) {}, ), @@ -178,7 +178,7 @@ void main() { onSignupTapped: () { onSignupTappedCalled = true; }, - onLoggedIn: (_) {}, + onLoggedIn: (BuildContext context, _) {}, onSocialAuthButtonPressed: (_) {}, onLoginError: (_) {}, ), @@ -222,7 +222,7 @@ void main() { greetingLabel: greetingLabel, onResetPassTapped: () {}, onSignupTapped: () {}, - onLoggedIn: (_) { + onLoggedIn: (BuildContext context, _) { onLoggedInCalled = true; }, onSocialAuthButtonPressed: (_) {}, @@ -263,7 +263,7 @@ void main() { onLoginError: (_) { onLoginErrorCalled = true; }, - onLoggedIn: (_) {}, + onLoggedIn: (BuildContext context, _) {}, onSocialAuthButtonPressed: (_) {}, ), )); @@ -298,7 +298,7 @@ void main() { onResetPassTapped: () {}, onSignupTapped: () {}, onLoginError: (_) {}, - onLoggedIn: (_) {}, + onLoggedIn: (BuildContext context, _) {}, onSocialAuthButtonPressed: (_) {}, ), )); @@ -332,7 +332,7 @@ void main() { onResetPassTappedCalled = true; }, onSignupTapped: () {}, - onLoggedIn: (_) {}, + onLoggedIn: (BuildContext context, _) {}, onSocialAuthButtonPressed: (_) {}, onLoginError: (_) {}, ), @@ -378,7 +378,7 @@ void main() { greetingLabel: greetingLabel, onResetPassTapped: () {}, onSignupTapped: () {}, - onLoggedIn: (_) {}, + onLoggedIn: (BuildContext context, _) {}, onSocialAuthButtonPressed: (_) { onSocialAuthButtonPressedCalled = true; }, @@ -424,7 +424,7 @@ void main() { greetingLabel: greetingLabel, onResetPassTapped: () {}, onSignupTapped: () {}, - onLoggedIn: (_) {}, + onLoggedIn: (BuildContext context, _) {}, onSocialAuthButtonPressed: (_) {}, onLoginError: (_) {}, ),