Skip to content

Commit

Permalink
fix(deriv_auth): fix 2fa for social login (#418)
Browse files Browse the repository at this point in the history
* fix(deriv_auth): fix 2fa for social login

* docs: update layout documentation

* chore(deriv_auth): sort imports
  • Loading branch information
sahani-deriv authored Jan 26, 2024
1 parent 1f6eb85 commit 5a1001c
Show file tree
Hide file tree
Showing 3 changed files with 178 additions and 14 deletions.
126 changes: 126 additions & 0 deletions packages/deriv_auth/docs/deriv_auth_layouts.md
Original file line number Diff line number Diff line change
@@ -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,
),
```
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<Deriv2FALayout> createState() => _Deriv2FALayoutState();
Expand Down Expand Up @@ -117,11 +143,23 @@ class _Deriv2FALayoutState extends State<Deriv2FALayout> {
FocusManager.instance.primaryFocus?.unfocus();

if (!_isLoading()) {
context.read<DerivAuthCubit>().systemLogin(
email: widget.email,
password: widget.password,
otp: _otpController.text,
);
if (widget.oneAllConnectionToken != null) {
context.read<DerivAuthCubit>().socialLogin(
oneAllConnectionToken: widget.oneAllConnectionToken!,
otp: _otpController.text,
);
} else if (widget.socialAuthDto != null) {
context.read<DerivAuthCubit>().socialAuth(
socialAuthDto: widget.socialAuthDto!,
otp: _otpController.text,
);
} else if (widget.email != null && widget.password != null) {
context.read<DerivAuthCubit>().systemLogin(
email: widget.email!,
password: widget.password!,
otp: _otpController.text,
);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -35,7 +34,8 @@ void main() {
settle: false,
BlocProvider<DerivAuthCubit>.value(
value: authCubit,
child: Deriv2FALayout(email: mockEmail, password: mockPassword),
child: Deriv2FALayout.systemLogin(
email: mockEmail, password: mockPassword),
),
);

Expand Down Expand Up @@ -63,7 +63,7 @@ void main() {
await $.pumpApp(
BlocProvider<DerivAuthCubit>.value(
value: authCubit,
child: Deriv2FALayout(
child: Deriv2FALayout.systemLogin(
email: mockEmail,
password: mockPassword,
),
Expand Down

0 comments on commit 5a1001c

Please sign in to comment.