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

Disabling the inital implementation of Account Linking #2001

Merged
merged 2 commits into from
May 9, 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
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore_for_file: use_build_context_synchronously

import 'package:app/blocs/blocs.dart';
import 'package:app/models/enum_constants.dart';
import 'package:app/screens/email_authentication/email_auth_widgets.dart';
Expand All @@ -8,7 +6,6 @@
import 'package:app/utils/utils.dart';
import 'package:app/widgets/widgets.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
Expand Down Expand Up @@ -211,39 +208,6 @@
);
}

Future<void> linkAccounts() async {
final emailAuthModel =
context.read<EmailVerificationBloc>().state.emailAuthModel;

final emailCredential = EmailAuthProvider.credentialWithLink(
emailLink: emailAuthModel.signInLink,
email: emailAuthModel.emailAddress,
);

final user = FirebaseAuth.instance.currentUser;

try {
if (user != null) {
await user.linkWithCredential(emailCredential);
context.read<EmailVerificationBloc>().add(
const SetEmailVerificationStatus(
AuthenticationStatus.success,
),
);
await AirqoApiClient().syncPlatformAccount();
}
} catch (error) {
context.read<EmailVerificationBloc>().add(
const SetEmailVerificationStatus(
AuthenticationStatus.error,
),
);
if (kDebugMode) {
print('Error linking accounts: $error');
}
}
}

Future<void> _authenticate() async {
loadingScreen(context);

Expand All @@ -255,36 +219,27 @@
);

try {
final currentUser = FirebaseAuth.instance.currentUser;
if (currentUser != null) {

Navigator.pop(context);

await _linkAccountWithEmailCredential(currentUser, emailCredential);

await AirqoApiClient().syncPlatformAccount();
} else {
final bool authenticationSuccessful =
await CustomAuth.firebaseSignIn(emailCredential);
if (!mounted) return;

if (!authenticationSuccessful) {
Navigator.pop(context);
await showDialog<void>(
context: context,
barrierDismissible: false,
builder: (BuildContext _) {
return const AuthFailureDialog();
},
);
return;
}
final bool authenticationSuccessful =
await CustomAuth.firebaseSignIn(emailCredential);
if (!mounted) return;

Check warning on line 224 in mobile/lib/screens/email_authentication/email_verification_screen.dart

View check run for this annotation

Codecov / codecov/patch

mobile/lib/screens/email_authentication/email_verification_screen.dart#L223-L224

Added lines #L223 - L224 were not covered by tests

context.read<EmailVerificationBloc>().add(
const SetEmailVerificationStatus(AuthenticationStatus.success));
Navigator.pop(context);

Check warning on line 226 in mobile/lib/screens/email_authentication/email_verification_screen.dart

View check run for this annotation

Codecov / codecov/patch

mobile/lib/screens/email_authentication/email_verification_screen.dart#L226

Added line #L226 was not covered by tests

Navigator.pop(context);
if (authenticationSuccessful) {
context
.read<EmailVerificationBloc>()
.add(const SetEmailVerificationStatus(

Check warning on line 231 in mobile/lib/screens/email_authentication/email_verification_screen.dart

View check run for this annotation

Codecov / codecov/patch

mobile/lib/screens/email_authentication/email_verification_screen.dart#L229-L231

Added lines #L229 - L231 were not covered by tests
AuthenticationStatus.success,
));
await AppService.postSignInActions(context);
} else {
await showDialog<void>(
context: context,

Check warning on line 237 in mobile/lib/screens/email_authentication/email_verification_screen.dart

View check run for this annotation

Codecov / codecov/patch

mobile/lib/screens/email_authentication/email_verification_screen.dart#L236-L237

Added lines #L236 - L237 were not covered by tests
barrierDismissible: false,
builder: (BuildContext _) {

Check warning on line 239 in mobile/lib/screens/email_authentication/email_verification_screen.dart

View check run for this annotation

Codecov / codecov/patch

mobile/lib/screens/email_authentication/email_verification_screen.dart#L239

Added line #L239 was not covered by tests
return const AuthFailureDialog();
},
);
}
} catch (exception, stackTrace) {
Navigator.pop(context);
Expand All @@ -299,11 +254,6 @@
}
}

Future<void> _linkAccountWithEmailCredential(
User currentUser, AuthCredential emailCredential) async {
await currentUser.linkWithCredential(emailCredential);
}

Future<bool> onWillPop() {
final now = DateTime.now();

Expand All @@ -323,4 +273,4 @@

return Future.value(false);
}
}
}
Loading
Loading