Skip to content

Commit

Permalink
feat: option to email support login error (#880)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nirajn2311 authored Mar 27, 2023
1 parent dfa971e commit c39655f
Showing 1 changed file with 50 additions and 2 deletions.
52 changes: 50 additions & 2 deletions mobile-app/lib/service/authentication/authentication_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:freecodecamp/models/main/user_model.dart';
import 'package:freecodecamp/ui/views/auth/privacy_view.dart';
import 'package:pretty_dio_logger/pretty_dio_logger.dart';
import 'package:stacked_services/stacked_services.dart';
import 'package:url_launcher/url_launcher.dart';

class AuthenticationService {
static final AuthenticationService _authenticationService =
Expand Down Expand Up @@ -130,6 +131,7 @@ class AuthenticationService {

Future<void> login(BuildContext context) async {
late final Credentials creds;
FccUserModel? user;
Response? res;

showDialog(
Expand Down Expand Up @@ -182,6 +184,8 @@ class AuthenticationService {
extractCookies(res);
await writeTokensToStorage();
await fetchUser();

user = await userModel;
} on DioError catch (e) {
Navigator.pop(context);
if (e.response != null) {
Expand Down Expand Up @@ -239,10 +243,54 @@ class AuthenticationService {
),
);
}
} catch (e, stacktrace) {
Navigator.pop(context);
String supportEmail = Uri.encodeComponent('[email protected]');
String subject = Uri.encodeComponent('Error logging in to mobile app');
String body = Uri.encodeComponent(
'Please email the below error to [email protected]\n\n${e.toString()}\n${stacktrace.toString()}');
showDialog(
context: context,
barrierDismissible: false,
routeSettings: const RouteSettings(
name: 'Login View - Error',
),
builder: (context) => AlertDialog(
backgroundColor: const Color(0xFF2A2A40),
title: const Text('Error'),
content: SelectableText(
'Please email the below error to [email protected]\n\n${e.toString()}\n${stacktrace.toString()}',
),
scrollable: true,
actions: [
TextButton(
style: TextButton.styleFrom(
backgroundColor: const Color(0xFF0a0a23),
),
onPressed: () async {
logout();
await launchUrl(Uri.parse(
'mailto:$supportEmail?subject=$subject&body=$body'));
Navigator.pop(context);
},
child: const Text('Email Error'),
),
TextButton(
style: TextButton.styleFrom(
backgroundColor: const Color(0xFF0a0a23),
),
onPressed: () {
logout();
Navigator.pop(context);
},
child: const Text('Close'),
),
],
),
);
rethrow;
}

final user = await userModel;

if (user != null && user.acceptedPrivacyTerms == false) {
bool? quincyEmails = await Navigator.push(
context,
Expand Down

0 comments on commit c39655f

Please sign in to comment.