Skip to content

Commit c39655f

Browse files
authored
feat: option to email support login error (#880)
1 parent dfa971e commit c39655f

File tree

1 file changed

+50
-2
lines changed

1 file changed

+50
-2
lines changed

mobile-app/lib/service/authentication/authentication_service.dart

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import 'package:freecodecamp/models/main/user_model.dart';
1313
import 'package:freecodecamp/ui/views/auth/privacy_view.dart';
1414
import 'package:pretty_dio_logger/pretty_dio_logger.dart';
1515
import 'package:stacked_services/stacked_services.dart';
16+
import 'package:url_launcher/url_launcher.dart';
1617

1718
class AuthenticationService {
1819
static final AuthenticationService _authenticationService =
@@ -130,6 +131,7 @@ class AuthenticationService {
130131

131132
Future<void> login(BuildContext context) async {
132133
late final Credentials creds;
134+
FccUserModel? user;
133135
Response? res;
134136

135137
showDialog(
@@ -182,6 +184,8 @@ class AuthenticationService {
182184
extractCookies(res);
183185
await writeTokensToStorage();
184186
await fetchUser();
187+
188+
user = await userModel;
185189
} on DioError catch (e) {
186190
Navigator.pop(context);
187191
if (e.response != null) {
@@ -239,10 +243,54 @@ class AuthenticationService {
239243
),
240244
);
241245
}
246+
} catch (e, stacktrace) {
247+
Navigator.pop(context);
248+
String supportEmail = Uri.encodeComponent('[email protected]');
249+
String subject = Uri.encodeComponent('Error logging in to mobile app');
250+
String body = Uri.encodeComponent(
251+
'Please email the below error to [email protected]\n\n${e.toString()}\n${stacktrace.toString()}');
252+
showDialog(
253+
context: context,
254+
barrierDismissible: false,
255+
routeSettings: const RouteSettings(
256+
name: 'Login View - Error',
257+
),
258+
builder: (context) => AlertDialog(
259+
backgroundColor: const Color(0xFF2A2A40),
260+
title: const Text('Error'),
261+
content: SelectableText(
262+
'Please email the below error to [email protected]\n\n${e.toString()}\n${stacktrace.toString()}',
263+
),
264+
scrollable: true,
265+
actions: [
266+
TextButton(
267+
style: TextButton.styleFrom(
268+
backgroundColor: const Color(0xFF0a0a23),
269+
),
270+
onPressed: () async {
271+
logout();
272+
await launchUrl(Uri.parse(
273+
'mailto:$supportEmail?subject=$subject&body=$body'));
274+
Navigator.pop(context);
275+
},
276+
child: const Text('Email Error'),
277+
),
278+
TextButton(
279+
style: TextButton.styleFrom(
280+
backgroundColor: const Color(0xFF0a0a23),
281+
),
282+
onPressed: () {
283+
logout();
284+
Navigator.pop(context);
285+
},
286+
child: const Text('Close'),
287+
),
288+
],
289+
),
290+
);
291+
rethrow;
242292
}
243293

244-
final user = await userModel;
245-
246294
if (user != null && user.acceptedPrivacyTerms == false) {
247295
bool? quincyEmails = await Navigator.push(
248296
context,

0 commit comments

Comments
 (0)