From 5a1001c5d6411baa9c07407db4794bf594cec9a9 Mon Sep 17 00:00:00 2001 From: sahani-deriv <125638269+sahani-deriv@users.noreply.github.com> Date: Fri, 26 Jan 2024 15:13:28 +0800 Subject: [PATCH] fix(deriv_auth): fix 2fa for social login (#418) * fix(deriv_auth): fix 2fa for social login * docs: update layout documentation * chore(deriv_auth): sort imports --- .../deriv_auth/docs/deriv_auth_layouts.md | 126 ++++++++++++++++++ .../layouts/deriv_2fa_layout.dart | 60 +++++++-- .../layouts/deriv_2fa_layout_test.dart | 6 +- 3 files changed, 178 insertions(+), 14 deletions(-) create mode 100644 packages/deriv_auth/docs/deriv_auth_layouts.md diff --git a/packages/deriv_auth/docs/deriv_auth_layouts.md b/packages/deriv_auth/docs/deriv_auth_layouts.md new file mode 100644 index 000000000..5443a9486 --- /dev/null +++ b/packages/deriv_auth/docs/deriv_auth_layouts.md @@ -0,0 +1,126 @@ +## Deriv Auth Layouts + +### - Get Started Flow +- **Get Started Layout** + ``` dart + DerivGetStartedLayout( + slides: [ + // List of instances of DerivGetStartedSlideModel + ], + appLogoIconPath: appLogoIconPath, + backgroundImagePath: backgroundImagePath, + onLoginTapped: () {}, + onSignupTapped: () {}, + ); + ``` +### - Login Flow +- **Login Layout** + ``` dart + DerivLoginLayout( + welcomeLabel: 'Welcome back!', + greetingLabel: + 'Log in to your Deriv account to start trading and investing.', + onResetPassTapped: () { + // Navigate to reset password page + }, + onSignupTapped: () { + // Navigate to signup page + }, + onLoginError: (DerivAuthErrorState error) { + // Show error message + }, + onLoggedIn: (DerivAuthLoggedInState state) { + // Navigate to home page + }, + onSocialAuthButtonPressed: (SocialAuthProvider provider) { + // Handle social auth + }, + ); + ``` +- **2FA Layout** + ``` dart + // For 2FA with email and password + Deriv2FALayout.systemLogin( + email: email, + password: password, + ); + // For 2FA with social auth + Deriv2FALayout.socialLogin( + socialAuthDto: socialAuthDto, + ); + // For 2FA with oneAll social login + Deriv2FALayout.oneAll( + oneAllConnectionToken: oneAllConnectionToken, + ); + ``` + +### - Signup Flow +- **Signup Layout** + ``` dart + DerivSignupLayout( + signupPageLabel: 'Start trading with Deriv', + signupPageDescription: + 'Join over 1 million traders worldwide who loves trading at Deriv.', + onSocialAuthButtonPressed: (SocialAuthProvider provider) {}, + onSingupError: (DerivSignupErrorState error) {}, + onSingupEmailSent: (String email) {}, + onSignupPressed: () {}, + onLoginTapped: () {}, + ); + ``` +- **Verify Email Layout** + ``` dart + DerivVerifyEmailLayout( + email: email, + onEmailNotReceivedPressed: () {}, + ); + ``` +- **Email not received layout** + ``` dart + DerivEmailNotReceivedLayout( + onReEnterEmailPressed: () {}, + ); + ``` +- **Verification Done Layout** + ``` dart + DerivVerificationDoneLayout( + verificationCode: '123456', + onContinuePressed: () {}, + ); + ``` +- **Country Selection Layout** + ``` dart + DerivCountrySelectionLayout( + onNextPressed: () {}, + verificationCode: '123456', + residences: residences, + ); + ``` +- **Set Password Layout** + ``` dart + DerivSetPasswordLayout( + onDerivAuthState: (BuildContext, DerivAuthState) {}, + onDerivSignupState: (BuildContext, DerivSignupState) {}, + onPreviousPressed: () {}, + verificationCode: '123456', + residence: 'residence', + ); + ``` +### - Reset Password Flow + +- **Reset Password Layout** + ``` dart + DerivResetPassLayout( + onResetPassError: (String? error) {}, + ), + ``` + +- **Choose New Password Layout** + ``` dart + DerivChooseNewPassLayout( + onResetPassError: (String? error) {}, + onResetPassSucceed: () {}, + token: token, + ), + ``` + diff --git a/packages/deriv_auth/lib/features/login/presentation/layouts/deriv_2fa_layout.dart b/packages/deriv_auth/lib/features/login/presentation/layouts/deriv_2fa_layout.dart index 045deadb1..1658dc39a 100644 --- a/packages/deriv_auth/lib/features/login/presentation/layouts/deriv_2fa_layout.dart +++ b/packages/deriv_auth/lib/features/login/presentation/layouts/deriv_2fa_layout.dart @@ -1,5 +1,5 @@ -import 'package:deriv_auth/deriv_auth.dart'; import 'package:deriv_auth/core/helpers/assets.dart'; +import 'package:deriv_auth/deriv_auth.dart'; import 'package:deriv_theme/deriv_theme.dart'; import 'package:deriv_ui/deriv_ui.dart'; import 'package:flutter/material.dart'; @@ -9,18 +9,44 @@ import 'package:flutter_svg/flutter_svg.dart'; /// Two-factor-authentication page. class Deriv2FALayout extends StatefulWidget { - /// Initializes the two-factor-authentication page. - const Deriv2FALayout({ + /// Initializes the two-factor-authentication page for system login. + const Deriv2FALayout.systemLogin({ required this.email, required this.password, Key? key, - }) : super(key: key); + }) : oneAllConnectionToken = null, + socialAuthDto = null, + super(key: key); + + /// Initializes the two-factor-authentication page for social login. + const Deriv2FALayout.socialLogin({ + required this.socialAuthDto, + Key? key, + }) : email = null, + password = null, + oneAllConnectionToken = null, + super(key: key); + + /// Initializes the two-factor-authentication page for one all social login. + const Deriv2FALayout.oneAll({ + required this.oneAllConnectionToken, + Key? key, + }) : email = null, + password = null, + socialAuthDto = null, + super(key: key); /// User entered email in previous page. - final String email; + final String? email; /// User entered password in previous page. - final String password; + final String? password; + + /// For one all social login with 2FA. + final String? oneAllConnectionToken; + + /// For in house social login with 2FA. + final SocialAuthDto? socialAuthDto; @override State createState() => _Deriv2FALayoutState(); @@ -117,11 +143,23 @@ class _Deriv2FALayoutState extends State { FocusManager.instance.primaryFocus?.unfocus(); if (!_isLoading()) { - context.read().systemLogin( - email: widget.email, - password: widget.password, - otp: _otpController.text, - ); + if (widget.oneAllConnectionToken != null) { + context.read().socialLogin( + oneAllConnectionToken: widget.oneAllConnectionToken!, + otp: _otpController.text, + ); + } else if (widget.socialAuthDto != null) { + context.read().socialAuth( + socialAuthDto: widget.socialAuthDto!, + otp: _otpController.text, + ); + } else if (widget.email != null && widget.password != null) { + context.read().systemLogin( + email: widget.email!, + password: widget.password!, + otp: _otpController.text, + ); + } } } diff --git a/packages/deriv_auth/test/features/login/presentation/layouts/deriv_2fa_layout_test.dart b/packages/deriv_auth/test/features/login/presentation/layouts/deriv_2fa_layout_test.dart index 6bee01a22..5c3a3016d 100644 --- a/packages/deriv_auth/test/features/login/presentation/layouts/deriv_2fa_layout_test.dart +++ b/packages/deriv_auth/test/features/login/presentation/layouts/deriv_2fa_layout_test.dart @@ -2,7 +2,6 @@ import 'package:deriv_auth/core/models/landig_comany_model.dart'; import 'package:deriv_auth/deriv_auth.dart'; -import 'package:deriv_auth/features/login/presentation/layouts/deriv_2fa_layout.dart'; import 'package:deriv_ui/presentation/widgets/base_text_field.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -35,7 +34,8 @@ void main() { settle: false, BlocProvider.value( value: authCubit, - child: Deriv2FALayout(email: mockEmail, password: mockPassword), + child: Deriv2FALayout.systemLogin( + email: mockEmail, password: mockPassword), ), ); @@ -63,7 +63,7 @@ void main() { await $.pumpApp( BlocProvider.value( value: authCubit, - child: Deriv2FALayout( + child: Deriv2FALayout.systemLogin( email: mockEmail, password: mockPassword, ),