@@ -13,6 +13,7 @@ import 'package:freecodecamp/models/main/user_model.dart';
13
13
import 'package:freecodecamp/ui/views/auth/privacy_view.dart' ;
14
14
import 'package:pretty_dio_logger/pretty_dio_logger.dart' ;
15
15
import 'package:stacked_services/stacked_services.dart' ;
16
+ import 'package:url_launcher/url_launcher.dart' ;
16
17
17
18
class AuthenticationService {
18
19
static final AuthenticationService _authenticationService =
@@ -130,6 +131,7 @@ class AuthenticationService {
130
131
131
132
Future <void > login (BuildContext context) async {
132
133
late final Credentials creds;
134
+ FccUserModel ? user;
133
135
Response ? res;
134
136
135
137
showDialog (
@@ -182,6 +184,8 @@ class AuthenticationService {
182
184
extractCookies (res);
183
185
await writeTokensToStorage ();
184
186
await fetchUser ();
187
+
188
+ user = await userModel;
185
189
} on DioError catch (e) {
186
190
Navigator .pop (context);
187
191
if (e.response != null ) {
@@ -239,10 +243,54 @@ class AuthenticationService {
239
243
),
240
244
);
241
245
}
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 ;
242
292
}
243
293
244
- final user = await userModel;
245
-
246
294
if (user != null && user.acceptedPrivacyTerms == false ) {
247
295
bool ? quincyEmails = await Navigator .push (
248
296
context,
0 commit comments