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

fix(auth_single_entry): Update single entry auth #543

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -309,7 +309,7 @@ class _DerivLoginLayoutState extends State<DerivLoginLayout> {
}

if (state is DerivAuthLoggedInState) {
widget.onLoggedIn.call(state);
widget.onLoggedIn.call(context, state);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<DerivAuthCubit>.value(
value: derivAuthCubit,
),
BlocProvider<SocialAuthCubit>.value(
value: socialAuthCubit,
),
BlocProvider<DerivResetPassCubit>.value(
value: derivResetPassCubit,
),
BlocProvider<DerivSignupCubit>.value(
value: derivSignupCubit,
),
],
child: widget,
);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:deriv_auth/deriv_auth.dart';
import 'package:flutter/material.dart';

/// LoginPageModel class
class LoginPageModel {
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -27,12 +26,7 @@ class _LoginPageState extends State<LoginPage> {
Widget build(BuildContext context) => DerivLoginLayout(
welcomeLabel: AuthData().data.loginPageModel.welcomeLabel,
greetingLabel: AuthData().data.loginPageModel.greetingLabel,
onLoggedIn: (_) => Navigator.pushReplacement(
context,
MaterialPageRoute<void>(
builder: (BuildContext context) => const HomePage(),
),
),
onLoggedIn: AuthData().data.loginPageModel.onLoggedIn,
authErrorStateHandler:
AuthData().data.loginPageModel.authErrorStateHandler,
onLoginError: AuthData().data.loginPageModel.onLoginError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void main() {
greetingLabel: greetingLabel,
onResetPassTapped: () {},
onSignupTapped: () {},
onLoggedIn: (_) {},
onLoggedIn: (BuildContext context, _) {},
onSocialAuthButtonPressed: (SocialAuthDto p0) {},
onLoginError: (_) {},
),
Expand Down Expand Up @@ -104,7 +104,7 @@ void main() {
greetingLabel: greetingLabel,
onResetPassTapped: () {},
onSignupTapped: () {},
onLoggedIn: (_) {},
onLoggedIn: (BuildContext context, _) {},
onSocialAuthButtonPressed: (_) {},
onLoginError: (_) {},
),
Expand Down Expand Up @@ -143,7 +143,7 @@ void main() {
greetingLabel: greetingLabel,
onResetPassTapped: () {},
onSignupTapped: () {},
onLoggedIn: (_) {},
onLoggedIn: (BuildContext context, _) {},
onSocialAuthButtonPressed: (_) {},
onLoginError: (_) {},
),
Expand Down Expand Up @@ -178,7 +178,7 @@ void main() {
onSignupTapped: () {
onSignupTappedCalled = true;
},
onLoggedIn: (_) {},
onLoggedIn: (BuildContext context, _) {},
onSocialAuthButtonPressed: (_) {},
onLoginError: (_) {},
),
Expand Down Expand Up @@ -222,7 +222,7 @@ void main() {
greetingLabel: greetingLabel,
onResetPassTapped: () {},
onSignupTapped: () {},
onLoggedIn: (_) {
onLoggedIn: (BuildContext context, _) {
onLoggedInCalled = true;
},
onSocialAuthButtonPressed: (_) {},
Expand Down Expand Up @@ -263,7 +263,7 @@ void main() {
onLoginError: (_) {
onLoginErrorCalled = true;
},
onLoggedIn: (_) {},
onLoggedIn: (BuildContext context, _) {},
onSocialAuthButtonPressed: (_) {},
),
));
Expand Down Expand Up @@ -298,7 +298,7 @@ void main() {
onResetPassTapped: () {},
onSignupTapped: () {},
onLoginError: (_) {},
onLoggedIn: (_) {},
onLoggedIn: (BuildContext context, _) {},
onSocialAuthButtonPressed: (_) {},
),
));
Expand Down Expand Up @@ -332,7 +332,7 @@ void main() {
onResetPassTappedCalled = true;
},
onSignupTapped: () {},
onLoggedIn: (_) {},
onLoggedIn: (BuildContext context, _) {},
onSocialAuthButtonPressed: (_) {},
onLoginError: (_) {},
),
Expand Down Expand Up @@ -378,7 +378,7 @@ void main() {
greetingLabel: greetingLabel,
onResetPassTapped: () {},
onSignupTapped: () {},
onLoggedIn: (_) {},
onLoggedIn: (BuildContext context, _) {},
onSocialAuthButtonPressed: (_) {
onSocialAuthButtonPressedCalled = true;
},
Expand Down Expand Up @@ -424,7 +424,7 @@ void main() {
greetingLabel: greetingLabel,
onResetPassTapped: () {},
onSignupTapped: () {},
onLoggedIn: (_) {},
onLoggedIn: (BuildContext context, _) {},
onSocialAuthButtonPressed: (_) {},
onLoginError: (_) {},
),
Expand Down
Loading