Skip to content
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
Expand Up @@ -17,6 +17,8 @@ class FirebaseCrashlyticsService implements CrashReportingInterface {
Future<void> initialize() async {
try {
setupFlutterErrorHandling();
await _crashlyticsInstance.setCrashlyticsCollectionEnabled(true);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While enabling collection is good for production, hardcoding 'true' here might override environment-specific configurations (e.g., disabling crashlytics in dev). Consider using a configuration flag.

Suggested change
await _crashlyticsInstance.setCrashlyticsCollectionEnabled(true);
if (!kDebugMode) {
await _crashlyticsInstance.setCrashlyticsCollectionEnabled(true);
}
await _crashlyticsInstance.sendUnsentReports();

await _crashlyticsInstance.sendUnsentReports();
logger.i('Firebase Crashlytics initialized successfully');
} catch (e, stackTrace) {
logger.e(
Expand Down
42 changes: 22 additions & 20 deletions lib/core/services/oauth_service.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import 'dart:convert';
import 'dart:math';
import 'dart:io';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:sign_in_with_apple/sign_in_with_apple.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'dart:math';

import 'package:crypto/crypto.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:fpdart/fpdart.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:injectable/injectable.dart';
import 'package:trakli/core/utils/services/logger.dart' show logger;
import 'package:trakli/core/error/repository_error_handler.dart';
import 'package:trakli/core/error/exceptions.dart';
import 'package:sign_in_with_apple/sign_in_with_apple.dart';
import 'package:trakli/core/error/crash_reporting/crash_reporting_service.dart';
import 'package:trakli/core/error/exceptions.dart';
import 'package:trakli/core/error/failures/failures.dart';
import 'package:trakli/core/error/repository_error_handler.dart';
import 'package:trakli/core/utils/services/logger.dart' show logger;
import 'package:trakli/data/datasources/auth/auth_remote_data_source.dart';
import 'package:trakli/di/injection.dart';
import 'package:trakli/domain/entities/user_entity.dart';
import 'package:fpdart/fpdart.dart';
import 'package:trakli/core/error/failures/failures.dart';
import 'package:trakli/domain/repositories/auth_repository.dart';

/// Service to handle OAuth authentication with backend API integration.
Expand Down Expand Up @@ -111,15 +112,13 @@ class OAuthService {
} on FirebaseAuthException catch (e, stackTrace) {
logger.e('Google Sign-In Firebase error: ${e.code} - ${e.message}',
error: e);
await _crashReporting.recordError(
e,
stackTrace: stackTrace,
reason: 'Google Sign-In FirebaseAuthException',
information: {
'code': e.code,
'message': e.message ?? '',
}
);
await _crashReporting.recordError(e,
stackTrace: stackTrace,
reason: 'Google Sign-In FirebaseAuthException',
information: {
'code': e.code,
'message': e.message ?? '',
});
throw _mapFirebaseException(e);
}
});
Expand Down Expand Up @@ -151,7 +150,8 @@ class OAuthService {
nonce: nonce,
);
} on SignInWithAppleAuthorizationException catch (e, stackTrace) {
logger.e('Apple Sign-In authorization error: ${e.code}', error: e);
logger.e('Apple Sign-In authorization error: ${e.code} - ${e.message}',
error: e);

if (e.code == AuthorizationErrorCode.canceled) {
return const Left(Failure.cancel());
Expand All @@ -162,9 +162,11 @@ class OAuthService {
reason: 'Apple Sign-In authorization failed',
information: {
'code': e.code.name,
'message': e.message,
},
);
return const Left(Failure.unauthorizedError());
return Left(Failure.badRequest(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing from 'unauthorizedError' to 'badRequest' with a string message is a functional change. Ensure the UI layer is prepared to display this raw error message to users, as 'e.message' from Apple might contain technical jargon.

Suggested change
return Left(Failure.badRequest(
return Left(Failure.unauthorizedError(message: 'Apple Sign-In failed: ${e.message}'));

error: 'Apple Sign-In failed (${e.code.name}): ${e.message}'));
}

return RepositoryErrorHandler.handleApiCall<UserEntity>(() async {
Expand Down
6 changes: 2 additions & 4 deletions lib/presentation/auth/pages/login_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,14 @@ class _LoginScreenState extends State<LoginScreen> {
_OAuthButton(
label: LocaleKeys.loginGoogle.tr(),
iconPath: Assets.images.google,
onTap: () =>
context.read<OAuthCubit>().signInWithGoogle(),
onTap: () => context.read<OAuthCubit>().signInWithGoogle(),
),
if (Platform.isIOS) ...[
SizedBox(height: 10.h),
_OAuthButton(
label: LocaleKeys.loginApple.tr(),
iconPath: Assets.images.apple,
onTap: () =>
context.read<OAuthCubit>().signInWithApple(),
onTap: () => context.read<OAuthCubit>().signInWithApple(),
),
],
SizedBox(height: 14.h),
Expand Down
10 changes: 5 additions & 5 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ packages:
dependency: transitive
description:
name: characters
sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803
sha256: faf38497bda5ead2a8c7615f4f7939df04333478bf32e4173fcb06d428b5716b
url: "https://pub.dev"
source: hosted
version: "1.4.0"
version: "1.4.1"
charcode:
dependency: transitive
description:
Expand Down Expand Up @@ -1276,10 +1276,10 @@ packages:
dependency: transitive
description:
name: material_color_utilities
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
sha256: "9c337007e82b1889149c82ed242ed1cb24a66044e30979c44912381e9be4c48b"
url: "https://pub.dev"
source: hosted
version: "0.11.1"
version: "0.13.0"
meta:
dependency: transitive
description:
Expand Down Expand Up @@ -2150,5 +2150,5 @@ packages:
source: hosted
version: "3.1.3"
sdks:
dart: ">=3.8.0 <4.0.0"
dart: ">=3.9.0-0 <4.0.0"
flutter: ">=3.32.0"
Loading