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(deriv_auth): fix 2fa for social login #418

Merged
merged 3 commits into from
Jan 26, 2024
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
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
Loading