Skip to content

Fixes. feature/firebase-authentication-#31#33

Merged
RaulRinconX merged 5 commits intomainfrom
feature/firebase-authentication-#31
Oct 2, 2024
Merged

Fixes. feature/firebase-authentication-#31#33
RaulRinconX merged 5 commits intomainfrom
feature/firebase-authentication-#31

Conversation

@RaulRinconX
Copy link
Copy Markdown
Contributor

@RaulRinconX RaulRinconX commented Oct 1, 2024

This pull request introduces significant changes to the authentication flow by replacing the old login system with a new authentication bloc and adding support for Google Sign-In. Additionally, it includes updates to the build.gradle file and the app.dart file to support these changes.

Authentication Flow Updates:

Removed Old Login System:

  • Removed old login bloc files (login_bloc.dart, login_event.dart, login_state.dart) that managed the previous authentication system. [1] [2] [3]

Configuration Updates:

  • android/app/build.gradle: Updated minSdk version from flutter.minSdkVersion to 23.
  • lib/app.dart: Added import for the new registration screen and updated route definitions to include the registration screen. [1] [2]

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a registration screen for user sign-up.
    • Added Google Sign-In functionality for both sign-up and sign-in processes.
    • Enhanced authentication management using Firebase Authentication.
  • Bug Fixes

    • Resolved issues related to the previous login mechanism.
  • Refactor

    • Updated the login screen to utilize the new authentication bloc.
    • Transitioned from a stateless to a stateful widget for better state management.
  • Dependencies

    • Added new dependencies for Firebase and Google Sign-In support.
  • Documentation

    • Updated plugin registrations for Firebase Authentication on macOS.

@RaulRinconX RaulRinconX added the bug Something isn't working label Oct 1, 2024
@RaulRinconX RaulRinconX added this to the Sprint 2 milestone Oct 1, 2024
@RaulRinconX RaulRinconX self-assigned this Oct 1, 2024
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Oct 1, 2024

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces significant changes to the authentication flow of a Flutter application, primarily by implementing Firebase Authentication and Google Sign-In. It includes the addition of a new registration screen, refactoring of the login screen, and the creation of an AuthBloc to manage authentication events and states. The pubspec.yaml file is updated with new dependencies for Firebase and Google services, while the Android build configuration is adjusted to support the new features.

Changes

File Path Change Summary
android/app/build.gradle Updated minSdk version from flutter.minSdkVersion to 23.
lib/app.dart Added a new route for the registration screen ('/register').
lib/features/auth/presentation/bloc/auth_bloc.dart Introduced AuthBloc class for managing authentication events and states.
lib/features/auth/presentation/bloc/auth_event.dart Created AuthEvent and various event classes for authentication actions.
lib/features/auth/presentation/bloc/auth_state.dart Established AuthState and subclasses for different authentication states.
lib/features/auth/presentation/screens/login_screen.dart Refactored to use AuthBloc, added Google Sign-In button, and removed username input.
lib/features/auth/presentation/screens/register_screen.dart Introduced a new RegisterScreen class for user registration.
lib/features/auth/repository/auth_repository.dart Updated to use Firebase Authentication methods for sign-up and sign-in.
lib/main.dart Renamed LoginBloc to AuthBloc and updated instantiation in MultiBlocProvider.
pubspec.yaml Added dependencies for firebase_auth, google_sign_in, logger, and sign_button.
widgetbook/macos/Flutter/GeneratedPluginRegistrant.swift Registered FLTFirebaseAuthPlugin for Firebase Authentication on macOS.

Possibly related issues

  • feature/firebase-authentication #31: This PR addresses the confusion in the user authentication flow and improves the integration of Firebase Authentication, aligning with the objectives of the reported issue.

Possibly related PRs

Suggested labels

enhancement

Poem

🐰 In the garden where bunnies play,
New paths for login come into sway.
With Firebase magic, sign-ups are bright,
Google joins in, making it right!
Hops of joy for screens fresh and new,
A flutter of changes, just for you! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 19

🧹 Outside diff range and nitpick comments (12)
lib/features/auth/presentation/bloc/auth_state.dart (3)

10-16: LGTM with a minor suggestion: Consider adding @immutable annotation.

The AuthAuthenticated class is well-implemented with a final user field and a proper constructor. To further emphasize the immutability of this state, consider adding the @immutable annotation from the meta package.

You can add the annotation like this:

import 'package:meta/meta.dart';

@immutable
class AuthAuthenticated extends AuthState {
  // ... rest of the class
}

18-24: LGTM with the same minor suggestion: Consider adding @immutable annotation.

The AuthError class is well-implemented with a final errorMessage field and a proper constructor. As with the AuthAuthenticated class, consider adding the @immutable annotation to emphasize the immutability of this state.

You can add the annotation like this:

import 'package:meta/meta.dart';

@immutable
class AuthError extends AuthState {
  // ... rest of the class
}

1-26: LGTM: Well-structured and comprehensive authentication states.

The file provides a complete set of authentication states, covering initial, loading, authenticated, error, and unauthenticated scenarios. The use of an abstract base class AuthState allows for easy extension if more specific states are needed in the future.

For potential future improvement:
Consider adding a copyWith method to the AuthAuthenticated and AuthError classes. This would allow for easy creation of new instances with updated fields, which can be useful in more complex state management scenarios.

Example implementation for AuthAuthenticated:

class AuthAuthenticated extends AuthState {
  AuthAuthenticated(this.user);

  final User user;

  AuthAuthenticated copyWith({User? user}) {
    return AuthAuthenticated(user ?? this.user);
  }
}
lib/features/auth/presentation/bloc/auth_event.dart (1)

1-24: Great implementation of authentication events with a minor suggestion.

The auth_event.dart file is well-structured and implements a comprehensive set of authentication events. The code follows Dart and Flutter best practices, providing a clean and extensible foundation for the application's authentication system.

To further improve the code:

Consider adding brief documentation comments for each class to explain their purpose and usage. This will enhance code readability and maintainability, especially as the project grows. For example:

/// Represents a request to sign in with email and password.
class SignInRequested extends AuthEvent {
  // ... (existing code)
}

/// Represents a request to sign up with email and password.
class SignUpRequested extends AuthEvent {
  // ... (existing code)
}

/// Represents a request to sign in using Google authentication.
class SignInWithGoogleRequested extends AuthEvent {}

// ... (and so on for other classes)
lib/main.dart (1)

50-52: LGTM! Consider using a consistent naming convention for bloc creation.

The BlocProvider has been correctly updated to create an instance of AuthBloc instead of LoginBloc. This change aligns with the PR objective of introducing a new authentication bloc to manage authentication events and states.

For consistency with other bloc providers in this file, consider using a single-line lambda for the create function:

 BlocProvider<AuthBloc>(
-  create: (BuildContext context) =>
-      AuthBloc(authRepository: authRepository),
+  create: (BuildContext context) => AuthBloc(authRepository: authRepository),
 ),
lib/app.dart (1)

48-48: LGTM: New route for RegisterScreen added.

The new route for the RegisterScreen is correctly implemented and follows the existing structure. This addition aligns with the PR objectives of introducing a new registration screen.

Consider extracting route names to constants for better maintainability. For example:

class Routes {
  static const String splash = '/';
  static const String main = '/main';
  static const String login = '/login';
  static const String register = '/register';
}

Then use these constants in the routes map:

routes: <String, WidgetBuilder>{
  Routes.splash: (BuildContext context) => const SplashScreen(),
  Routes.main: (BuildContext context) => const MainLayout(),
  Routes.login: (BuildContext context) => const LoginScreen(),
  Routes.register: (BuildContext context) => const RegisterScreen(),
},

This approach would make it easier to manage and update route names in the future.

pubspec.yaml (3)

33-33: Approve Firebase Auth dependency, but consider updating.

The addition of firebase_auth aligns with the PR objectives. However, consider updating to the latest version (currently ^4.15.3) for potential bug fixes and improvements.

-  firebase_auth: ^5.3.1
+  firebase_auth: ^4.15.3

39-39: Approve Google Sign-In dependency, but consider updating.

The addition of google_sign_in aligns with the PR objectives. However, consider updating to the latest version (currently ^6.1.6) for potential bug fixes and improvements.

-  google_sign_in: ^6.2.1
+  google_sign_in: ^6.1.6

45-45: Approve sign_button dependency, but consider updating.

The addition of sign_button aligns with the PR objectives for implementing a Google Sign-In button. However, consider updating to the latest version (currently ^2.0.3) for potential bug fixes and improvements.

-  sign_button: ^2.0.6
+  sign_button: ^2.0.3
lib/features/auth/presentation/screens/register_screen.dart (1)

15-24: Consider adding input validation for email and password.

While the initialization and disposal of TextEditingControllers are correct, it would be beneficial to add input validation for the email and password fields. This can help ensure that users enter valid email addresses and strong passwords.

Would you like me to provide an example of how to implement input validation for these fields?

lib/features/auth/repository/auth_repository.dart (1)

1-3: Organize imports for clarity and consistency

Consider organizing the import statements alphabetically or grouping them by package type (e.g., external packages, internal packages) to improve readability.

Example:

-import 'package:firebase_auth/firebase_auth.dart';
-import 'package:google_sign_in/google_sign_in.dart';
-import 'package:logger/logger.dart';
+import 'package:firebase_auth/firebase_auth.dart';
+import 'package:google_sign_in/google_sign_in.dart';
+import 'package:logger/logger.dart';
lib/features/auth/presentation/screens/login_screen.dart (1)

155-162: Wrap the loading indicator in a dialog for better presentation.

Currently, the loading dialog returns a Center widget, which might not provide the desired modal appearance. Wrapping the CircularProgressIndicator in an AlertDialog or Dialog can improve the user interface.

Modify the _showLoadingDialog method:

 void _showLoadingDialog(BuildContext context) {
   showDialog(
     context: context,
     barrierDismissible: false,
     builder: (BuildContext context) {
-      return const Center(child: CircularProgressIndicator());
+      return const Dialog(
+        backgroundColor: Colors.transparent,
+        child: Center(child: CircularProgressIndicator()),
+      );
     },
   );
 }

This change provides a more standard dialog appearance for the loading indicator.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 37e96ef and 4114bfe.

⛔ Files ignored due to path filters (2)
  • pubspec.lock is excluded by !**/*.lock
  • widgetbook/pubspec.lock is excluded by !**/*.lock
📒 Files selected for processing (14)
  • android/app/build.gradle (1 hunks)
  • lib/app.dart (2 hunks)
  • lib/features/auth/presentation/bloc/auth_bloc.dart (1 hunks)
  • lib/features/auth/presentation/bloc/auth_event.dart (1 hunks)
  • lib/features/auth/presentation/bloc/auth_state.dart (1 hunks)
  • lib/features/auth/presentation/bloc/login_bloc.dart (0 hunks)
  • lib/features/auth/presentation/bloc/login_event.dart (0 hunks)
  • lib/features/auth/presentation/bloc/login_state.dart (0 hunks)
  • lib/features/auth/presentation/screens/login_screen.dart (2 hunks)
  • lib/features/auth/presentation/screens/register_screen.dart (1 hunks)
  • lib/features/auth/repository/auth_repository.dart (1 hunks)
  • lib/main.dart (2 hunks)
  • pubspec.yaml (1 hunks)
  • widgetbook/macos/Flutter/GeneratedPluginRegistrant.swift (1 hunks)
💤 Files with no reviewable changes (3)
  • lib/features/auth/presentation/bloc/login_bloc.dart
  • lib/features/auth/presentation/bloc/login_event.dart
  • lib/features/auth/presentation/bloc/login_state.dart
🔇 Additional comments (19)
lib/features/auth/presentation/bloc/auth_state.dart (3)

1-4: LGTM: Proper import and base class declaration.

The import of firebase_auth is correct and necessary for using the User type. The abstract AuthState class is well-defined as a base for all concrete auth states, following good object-oriented design principles.


6-8: LGTM: Clear and concise state representations.

The AuthInitial and AuthLoading classes are well-defined, extending the AuthState base class. They appropriately represent the initial and loading states of authentication without unnecessary complexity.


26-26: LGTM: Concise representation of unauthenticated state.

The AuthUnauthenticated class is well-defined, extending the AuthState base class. It appropriately represents the unauthenticated state without unnecessary complexity.

lib/features/auth/presentation/bloc/auth_event.dart (4)

1-2: LGTM: Abstract base class for authentication events.

The AuthEvent abstract class is correctly implemented as a base class for all authentication events. This follows best practices for the BLoC pattern in Flutter applications.


4-11: LGTM: Well-structured SignInRequested event class.

The SignInRequested class is correctly implemented:

  • It extends AuthEvent as expected.
  • Uses named parameters with the required keyword for email and password, ensuring these critical fields are always provided.
  • Follows Dart best practices for class structure and parameter handling.

13-20: LGTM: Consistent implementation of SignUpRequested event class.

The SignUpRequested class is correctly implemented and maintains consistency with SignInRequested:

  • Extends AuthEvent as expected.
  • Uses named parameters with the required keyword for email and password.
  • Follows the same structure as SignInRequested, which is good for maintaining code consistency.

22-24: LGTM: Concise implementation of Google auth and sign-out event classes.

The implementation of SignInWithGoogleRequested, SignUpWithGoogleRequested, and SignOutRequested classes is correct and follows best practices:

  • All extend AuthEvent as expected.
  • The classes are kept simple with no additional parameters, which is appropriate for these actions.
  • Separating Google sign-in and sign-up into distinct classes allows for more granular control in the future if needed.
  • The SignOutRequested class is correctly implemented as a simple event without parameters.

This structure provides a clear and extensible foundation for handling various authentication scenarios.

widgetbook/macos/Flutter/GeneratedPluginRegistrant.swift (2)

8-8: LGTM: Firebase Auth import added correctly.

The firebase_auth import has been added appropriately, grouped with other Firebase-related imports. This is necessary for the new Firebase Authentication functionality.


Line range hint 1-19: Overall: Firebase Authentication integration looks good.

The changes to this generated file are minimal and correctly implement the necessary components for Firebase Authentication on macOS. The import statement and plugin registration have been added appropriately, aligning with the PR objectives of integrating Firebase Authentication and Google Sign-In support.

android/app/build.gradle (1)

29-29: Verify Firebase SDK requirements and consider implications of increased minSdk.

The minSdk has been updated from a variable to a hardcoded value of 23 (Android 6.0 Marshmallow). While this change likely supports the new Firebase Authentication and Google Sign-In features, it's important to consider the following:

  1. This change may exclude older devices from using the app. Verify if this aligns with your target audience and device support strategy.
  2. Ensure that 23 is the minimum SDK version required by the Firebase SDK and Google Sign-In libraries you're using.
  3. This change provides access to runtime permissions and other features introduced in Android 6.0, which may be beneficial for your authentication implementation.
  4. The hardcoded value ensures consistency but reduces flexibility. Consider if this approach aligns with your project's build configuration strategy.

To confirm the Firebase SDK requirements, please run the following command:

This will help verify if the Firebase SDK version used in the project necessitates this minSdk change.

lib/main.dart (2)

Line range hint 1-61: Summary: AuthBloc integration looks good.

The changes in this file successfully integrate the new AuthBloc into the application's main entry point. The modifications are minimal yet significant, reflecting the transition from LoginBloc to AuthBloc as outlined in the PR objectives. The overall structure of the file remains intact, maintaining the existing setup for other blocs and Firebase initialization.

These changes lay the groundwork for the new authentication system, including support for Google Sign-In, as mentioned in the PR summary. The integration appears seamless and doesn't introduce any apparent issues.


2-2: LGTM! Verify AuthBloc usage throughout the codebase.

The import statement has been correctly updated to reflect the change from LoginBloc to AuthBloc. This aligns with the PR objective of replacing the old login system with a new authentication bloc.

Let's verify that AuthBloc is consistently used throughout the codebase:

lib/app.dart (2)

5-5: LGTM: Import statement for RegisterScreen.

The import statement for the RegisterScreen is correctly placed and follows the existing import structure. This import is necessary for the new route added later in the file.


Line range hint 1-50: Summary: Successfully integrated RegisterScreen into the app's routing.

The changes in this file effectively integrate the new RegisterScreen into the application's routing system. The additions are minimal, focused, and consistent with the existing code structure. These changes align well with the PR objectives of enhancing the authentication flow by introducing a new registration screen.

A few points to note:

  1. The import statement for RegisterScreen is correctly placed.
  2. The new route for registration is properly added to the routes map.
  3. The overall structure and organization of the MyApp class remain intact.

These changes provide a solid foundation for the new registration functionality while maintaining the existing app structure.

pubspec.yaml (3)

Line range hint 48-49: Approve indentation correction.

The indentation correction for flutter_test under dev_dependencies improves the readability of the file. This is a good practice.


Line range hint 33-49: Summary of pubspec.yaml changes

The changes to pubspec.yaml align well with the PR objectives for implementing Firebase Authentication and Google Sign-In. The addition of dependencies is appropriate, but there are opportunities for minor improvements:

  1. Consider updating all added dependencies to their latest versions as suggested in the individual comments.
  2. Clarify the intended use of the logger package in the context of this authentication flow implementation.

Once these minor adjustments are made, the pubspec.yaml changes will be fully approved.


41-41: Approve logger dependency, but clarify usage and consider updating.

The addition of logger is a good practice for debugging and monitoring. However, its specific use in this PR is not clear from the objectives. Please clarify how it will be used in the authentication flow. Also, consider updating to the latest version (currently ^2.0.2+1) for potential bug fixes and improvements.

-  logger: ^2.4.0
+  logger: ^2.0.2+1

To verify the usage of the logger:

lib/features/auth/presentation/screens/register_screen.dart (2)

1-13: LGTM: Imports and class declaration look good.

The imports cover all necessary packages for the functionality, and the RegisterScreen class is correctly defined as a stateful widget.


1-163: Overall, good implementation with room for improvements.

The RegisterScreen implementation is well-structured and follows Flutter and Bloc pattern best practices. It successfully implements both email/password and Google Sign-In registration options. However, there are several areas where the code could be enhanced:

  1. Add input validation for email and password fields.
  2. Improve error handling, especially for specific registration errors and Google Sign-Up.
  3. Implement a timeout mechanism for the loading dialog.
  4. Consider adding more user-friendly error messages and displays.

These improvements will enhance the user experience and make the registration process more robust and user-friendly.

Comment thread widgetbook/macos/Flutter/GeneratedPluginRegistrant.swift
Comment thread lib/features/auth/presentation/screens/register_screen.dart
Comment thread lib/features/auth/presentation/screens/register_screen.dart
Comment thread lib/features/auth/presentation/screens/register_screen.dart
Comment thread lib/features/auth/presentation/bloc/auth_bloc.dart
Comment thread lib/features/auth/repository/auth_repository.dart
Comment thread lib/features/auth/presentation/screens/login_screen.dart Outdated
Comment thread lib/features/auth/presentation/screens/login_screen.dart Outdated
Comment thread lib/features/auth/presentation/screens/login_screen.dart
Comment thread lib/features/auth/presentation/screens/login_screen.dart Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: DONE

Development

Successfully merging this pull request may close these issues.

2 participants